Mutable and immutable

In Scala, you will find mutable and immutable collections. A collection can have a mutable implementation and an immutable implementation. That's the reason why, in Java, a List can't be both a LinkedList and an ArrayList, but List has a LinkedList implementation and an ArrayList implementation. The following figure shows all collections in the package scala.collection.immutable:

Figure 2: All collections in package scala.collection.immutable

Scala imports the immutable collections by default, and if you need to use a mutable one, then you need to import it yourself. Now to get a brief overview of all collections in package scala.collection.mutable, refer to the following diagram:

Figure 3: All collections in package Scala.collection.mutable

In every OOP and functional programming language, an array is an important collection package that helps us to store data objects so that, later on, we can access them very easily as well. In the next subsection, we will see a detailed discussion on arrays with some examples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.69.49