Overview
Scala's collection classes can be sliced from three dimensions:
- Mutable and immutable collections (immutable and mutable collections)
- Static and Lazy load collection (Eager and delayed evaluation)
- Serial and parallel compute sets (sequential and parallel evaluation)
About the first dimension I don't think we need to introduce any more. As for the second dimension, it is explained in this way, first of all we explain a concept: transformation, a large number of operations in the collection is to "transform" a set into another set, such as Map,filter and so on. The difference between the eager and delayed collections is that the eager collection always allocates memory for the element immediately, and when a transform action is encountered, the eager collection evaluates directly and returns the result, while the delayed collection delays execution as late as possible. Execution is not performed until the result must be returned. This is very similar to the transformation and action in the Spark RDD operation.
In the existing collection, only the stream is lasy, and all other collections are static (Eager) loaded. But you can easily convert a static collection to lazy, which is to create a view.
Collection type Overview
Immutable Collectionimmutable Seq
Seq is divided into two main categories: indexed sequences and linear sequences,indexed sequences imply that this collection has a higher performance in random reads (similar to arrays in data structures). Linear sequences implies that this collection is more advantageous in head and tail operations and sequential traversal (similar to a bidirectional list in a data structure)
When using SEQ, the specific class used by default is list, and the specific class used by default when using Indexedseq is a vector.
scala> val seq = Seq(1,2,3)seq: Seq[Int] = List(123)scala> val indexedSeq = IndexedSeq(1,2,3)indexedSeq: IndexedSeq[Int] = Vector(123)
Immutable Set
Immutable Map
Mutable Seq
How to select a collection class characteristics comparison of various immutable sequence
Comparison of characteristics of various mutable sequence
Comparison of the characteristics of various maps
Comparison of the characteristics of various set
Note: This class diagram is referenced from "Beginning Scala" and the form is referenced from "Scala Cookbook"
Scala Collection Collection