Scala - Collections
Scala provides a nice collection implementation that provides some abstraction of collection types.
Scala collections are divided into variable and immutable collections.
Variable collections can be updated or extended where appropriate. This means you can modify, add, and remove elements of a collection.
The immutable collection class, by contrast, never changes. However, you can still simulate adding, removing, or updating operations. But these operations will return a new collection in each case, while leaving the original collection unchanged.
Next we will introduce you to several common collection types:
|Sr.No||Collections with Description|
The characteristic of List is that its elements are stored in a linear manner, and duplicate objects can be stored in the collection.
Set is the simplest collection. Objects in a collection are not sorted in a specific way, and there are no duplicate objects.
A Map is a collection of key and value objects, each of which contains a pair of key and value objects.
Tuples are collections of different types of values
Option[T] represents a container that may contain values or may not contain values.
An iterator is not a container, but rather a method of accessing elements within a container one by one.
The following code determines the definition of all the above collection types:
// Definition integer List val x = List(1,2,3,4) // definition Set val x = Set(1,3,5,7) // definition Map val x = Map("one" -> 1, "two" -> 2, "three" -> 3) // Create a tuple of two different types of elements val x = (10, "welookups") // definition Option val x:Option[Int] = Some(5)