scala集合中添加元素
In Scala, lists are immutable data structures in which adding new elements is not allowed. So, here we will solve this problem that is generally done in functional programming paradigms.
在Scala中,列表是不可变的数据结构,其中不允许添加新元素。 因此,在这里我们将解决通常在函数式编程范例中完成的问题。
To add elements to a list there are two methods,
要将元素添加到列表中 ,有两种方法:
1)将元素添加到Scala列表 (1) Appending elements to Scala list)
As the list is immutable when adding a new element to it, we will append an element to a new list.
由于添加新元素时列表是不可变的,因此我们将元素添加到新列表中 。
Done using the following operators,
使用以下运算符完成,
Prepending operator (::)
前置运算符( : :)
Ap