Scala-Collections Quick Reference
2 min readOct 15, 2023
Scala provides a rich set of collections to work with data. These collections are divided into two main categories: mutable and immutable.
Here are some common Scala collections with examples:
Immutable Collections
List
- An ordered collection of elements.
- Elements are immutable; you can’t modify a list, but you can create new lists by adding or removing elements.
Set
- An unordered collection of unique elements.
- Immutable, like lists.
Map
- A collection of key-value pairs.
- Immutable, like lists and sets.
Mutable Collections
Mutable List
- Similar to an immutable list but allows for in-place modifications.
Mutable Set
- Similar to an immutable set but allows for in-place modifications.
Mutable Map
- Similar to an immutable map but allows for in-place modifications.
Array
- A mutable, fixed-size collection.
These are just some of the most commonly used collections in Scala. Depending on your specific use case, you can choose between mutable and immutable collections.
Immutable collections are often preferred for their thread-safety and functional programming benefits, while mutable collections are useful for in-place updates.