
Option provides a container for zero or one element of a given type.Īn iterator is not a collection, but rather a way to access the elements of a collection one by one. Unlike an array or list, a tuple can hold objects with different types.

Any value can be retrieved based on its key. Scala's List is a linked list of type T.Ī set is a collection of pairwise different elements of the same type.Ī Map is a collection of key/value pairs.

This chapter throws light on the most commonly used collection types and most frequently used operations over those collections. We’ll demonstrate the basics of these classes in the following lessons. Mike Olson from Cloudera has called Spark the killer App for Scala.Not only is it written in Scala. When in doubt, it is better to start with an immutable collection and change it later if you need mutable ones. The main Scala collections classes you’ll use on a regular basis are: Map and Set come in both mutable and immutable versions. Immutable, sequential data-structures such as Vector, List, Range, HashMap or HashSet. Note that immutable collections may contain mutable items.įor some problems, mutable collections work better, and for others, immutable collections work better. The scala package contains core types like Int, Float, Array or Option which are accessible in all Scala compilation units without explicit qualification or imports. final class IterableOnceExtensionMethodsA trait IterableOnceOps+A, +CC, +C This implementation trait can be mixed into an IterableOnce to get the basic methods that are shared between Iterator and Iterable. The Scala Collections Library This chapter finishes our discussion of the standard library with a. The immutable collections are in the package, while the mutable.

Additionally, collections may be mutable (the contents of the reference can change) or immutable (the thing that a reference refers to is never changed). A template trait for collections which can be traversed either once only or one or more times. Trait withmethods for operating on collections of instances. Lazy collections have elements that may not consume memory until they are accessed, like Ranges. The collections may have an arbitrary number of elements or be bounded to zero or one element (e.g., Option).Ĭollections may be strict or lazy. Those containers can be sequenced, linear sets of items like List, Tuple, Option, Map, etc. Scala has a rich set of collection library. Scala Collections - Multi-Dimensional Array.
