July 2017
Intermediate to advanced
796 pages
18h 55m
English
As discussed earlier, Scala provides mutable and immutable collections. The Immutable collections are imported by default, but if you need to use a mutable one you need to import yourself. A list is an immutable collections, and it can be used if you want order between the elements to be preserved and duplicates to be kept. Let's demonstrate an example and see how lists preserve order and keep duplicated elements, and also check its immutability:
scala> val numbers = List(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)numbers: List[Int] = List(1, 2, 3, 4, 5, 1, 2, 3, 4, 5) scala> numbers(3) = 10 <console>:12: error: value update is not a member of List[Int] numbers(3) = 10 ^
You can define lists using two different building blocks. Nil represents the ...
Read now
Unlock full access