Collections · 27 of 42
Scala “encourages” using immutable collections (hence they are the ones used by default), however sometimes mutable collections might have some benefits, either for CPU / memory performance, for code readability or simply a matter of preference. As we saw earlier, Scala provides concrete mutable collections in scala.collection.mutable.
mutable; this might not seem useful for ArrayBuffer, but it will for scala.collection.mutable.MapArrayBuffer is more or less the equivalent of Java’s java.util.ArrayList, which is backed by an arrayListBuffer is the mutable partner for Scala’s immutable List, implemented as a linked listimport scala.collection.mutable
mutable.ArrayBuffer(1, 2, 3)
mutable.ListBuffer("a", "b", "c")
mutable.Set(0.1, 0.2, 0.3)
mutable.Map("one" -> 1, "two" -> 2)