O'Reilly logo

Pragmatic Scala by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Common Scala Collections

Scala has three main types of collections:

  • List—as you’d expect, an ordered collection of objects

  • Set—an unordered collection

  • Map—a dictionary of key-value pairs

Scala favors immutable collections, even though mutable versions are also available. If you want to modify a collection and if all the operations on the collection are all within a single thread, you can choose a mutable collection. However, if you plan to use the collection across threads or actors, the immutable collections are better. Immutable collections are thread safe, free from side effects, and help with program correctness. You can choose between these versions by selecting a class in one of these two packages: scala.collection.mutable or scala.collection.immutable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required