Scala Collections – Lists, Sequences & Vectors
Below, I have provided some of the collections which are usually the most used. Starting from the regular ones like Sequences, Lists, Maps, Sets we go on to discuss some of the more interesting ones like Vectors, Streams. Lists List is probably the easiest to understand and hence most used data structure/collection. In scala a list is implemented as a class. I quote A class for immutable linked lists representing ordered collections of elements of type A By default, all lists are immutable. However the devil is in the detail. Check out the scala documentation here. Despite being an immutable collection, the implementation uses mutable state internally during construction. These state changes are invisible in single-threaded code but can lead to race conditions in some multi-threaded scenarios You can declare lists in various ways and they are documented below Lists are efficient when the programs which use them are only … Read more