Chapter 3. Collections and the Joy of Immutability
In this chapter, we're going to explore Scala's collections classes and how to use them. Most Scala collection classes are immutable, meaning that once they are instantiated, the instances cannot be changed. You're used to immutability, as Java String
s are immutable. The conjunction of collections being immutable and providing powerful iteration features leads to more concise, higher-performance code that does extremely well in multicore, multithreaded concurrency situations.
Thinking Immutably
In Java, the most commonly used types are immutable. Once an instance is created, it cannot be changed. In Java, String, int, long, double
, and boolean
are all immutable data types. Of these, String is a ...
Get Beginning Scala now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.