Seq is an ordered sequence of values. It further breaks into two categories:
IndexSeqindicates that reandom access of elements is efficient through index. By default,
LinearSeqimplis that the collection can be efficiently split into head and tail. By default,
List, which is a singly linked list.
coll :+ elemappend
elem +: collprepend
Vector is the immutable equivalent of
ArrayBuffer. It is implemented as trees, and each node has up to 32 children.
It represents an immutable integer sequence. It only stores start, end, and imcrement. It is constructed using
Stack, Queue, PriorityQueue
Just as normal data structures.
List in Scala is either
Nil (empty) or an object with a
head element and a
tail (that is a
List). So a
List is like a node in a linked list.
:: operator makes a new list from given head and tail:
9 :: List (4, 2)
It is right-associative. It can also destructure the list into head and tail.
It is natural to use recursion to traverse a list.
LinkedList: you can modify the head (
lst.elem) and tail (
DoubleLinkedList: has a mutable
elem :: lst,
elem +: lst: a new list with
lst2 ::: lst,
lst2 ++: lst: a new list with