Well, a List
can be incredibly fast if the algorithm can be implemented solely with ::
, head
and tail
. I had an object lesson of that very recently, when I beat Java's split
by generating a List
instead of an Array
, and couldn't beat that with anything else.
However, List
has a fundamental problem: it doesn't work with parallel algorithms. I cannot split a List
into multiple segments, or concatenate it back, in an efficient manner.
There are other kinds of collections that can handle parallelism much better -- and Vector
is one of them. Vector
also has great locality -- which List
doesn't -- which can be a real plus for some algorithms.
So, all things considered, Vector
is the best choice unless you have specific considerations that make one of the other collections preferable -- for example, you might choose Stream
if you want lazy evaluation and caching (Iterator
is faster but doesn't cache), or List
if the algorithm is naturally implemented with the operations I mentioned.
By the way, it is preferable to use Seq
or IndexedSeq
unless you want a specific piece of API (such as List
's ::
), or even GenSeq
or GenIndexedSeq
if your algorithm can be run in parallel.
List<String> l = new ArrayList<String>()
Scala blogs would have you believe that everybody uses List in order to get persistent collection goodness - but is Vector general-purpose enough that we should be using it in List's place? – IteList
when I typeSeq()
at REPL. – AmritsarIndexedSeq
. – CalumniousSeq
is over three years old. As of Scala 2.11.4 (and earlier), the default concrete type ofSeq
isList
. – Pfeiffer