Templates by BIGtheme NET

Mutable and Immutable Collections

Basics
1) By default, Scala always picks immutable collections. For instance, if you just write Set without any prefix or without having imported Set from somewhere, you get an immutable set, and if you write Iterable you get an immutable iterable collection, because these are the default bindings imported from the scala package.
2) To get the mutable default versions, you need to write explicitly collection.mutable.Set, or collection.mutable.Iterable.
3) Immutable collections, by contrast, never change.
You have still operations that simulate additions, removals, or updates, but those operations will in
each case return a new collection and leave the old collection unchanged.
4) A useful convention if you want to use both mutable and immutable versions of collections is to import just the package collection.mutable.

import scala.collection.mutable

Then a word like Set without a prefix still refers to an an immutable collection,
whereas mutable.Set refers to the mutable counterpart.
scala.collection:
The high level class diagram.
1
scala.collection.immutable
2
scala.collection.mutable
3