26 Mutable Collections
Scala “encourages” using immutable collections (hence they are those 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.collections.mutable
- Best practice suggests that you prefix mutable collections with
mutable
, this might not seem useful forArrayBuffer
, but it will forscala.collections.mutable.Map
ArrayBuffer
is the more or less equivalent to java’sjava.util.ArrayList
which is backed by an arrayListBuffer
is the mutable partner for scala’s immutableList
, implemented as a Linked List- There are many other mutable collections types, see links below for more information