scala的列表合并
List is a collection of immutable data of the same data type. In Scala, the list represents linked-link data structures.
列表是相同数据类型的不可变数据的集合。 在Scala中,该列表表示链接数据结构。
Syntax to create a new list in Scala,
val list_name = List(item1, item2, item3...)
在Scala中合并列表 (Merge lists in Scala)
In Scala, we can merge/concatenate two lists into a single list. This will append the second list at the end of the first list.
在Scala中,我们可以将两个列表合并/合并为一个列表 。 这会将第二个列表附加在第一个列表的末尾。
You have to use a third variable to store the merged list in case of mutable lists. Else, we will have to use the ListBuffer Class(mutable lists) to store the results in the same variable.
如果是可变列表,则必须使用第三个变量来存储合并列表。 否则,我们将不得不使用ListBuffer类(可变列表)将结果存储在同一变量中。
Scala programming language provides three different ways to merge a list in Scala,
Scala编程语言提供了三种不同的方式来合并Scala中的列表,
Using ++ method
使用++方法
<