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 Strings 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 live online training, plus books, videos, and digital content from nearly 200 publishers.