Use the trait (interface) Seq (ordered list), Map (key value), Set, IndexedSeq, Array (for Java primitives) types and let the compiler choose the implementation. If you look at the source you will see a companion object for each. This uses a factory to find an implementation for you.
This page helped me. http://docs.scala-lang.org/overviews/collections/overview.html
The section on Concrete collections goes into the implementations.
Seq companion object:
object Seq extends SeqFactory[Seq] {
/** $genericCanBuildFromInfo */
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Seq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
def newBuilder[A]: Builder[A, Seq[A]] = immutable.Seq.newBuilder[A]
}
https://github.com/scala/scala/blob/v2.10.3/src/library/scala/collection/Seq.scala#L1
Look at the factory source to see how apply initializes the collection.
abstract class GenericCompanion[+CC[X] <: GenTraversable[X]] {
/** The underlying collection type with unknown element type */
type Coll = CC[_]
/** The default builder for `$Coll` objects.
* @tparam A the type of the ${coll}'s elements
*/
def newBuilder[A]: Builder[A, CC[A]]
/** An empty collection of type `$Coll[A]`
* @tparam A the type of the ${coll}'s elements
*/
def empty[A]: CC[A] = newBuilder[A].result
/** Creates a $coll with the specified elements.
* @tparam A the type of the ${coll}'s elements
* @param elems the elements of the created $coll
* @return a new $coll with elements `elems`
*/
def apply[A](elems: A*): CC[A] = {
if (elems.isEmpty) empty[A]
else {
val b = newBuilder[A]
b ++= elems
b.result
}
}
}
Update: I usually use Array for a mutable indexed collections type since it is easier to type, but Vector for immutable. The Scala style encourages using the immutable collections since making a new "copy" of an immutable data structure is performant because of the underlying implementation being done with Hash array mapped trie structures. http://en.wikipedia.org/wiki/Hash_array_mapped_trie