scala

# collection

#### package collection

Contains the base traits and objects needed to use and extend Scala's collection library.

#### Guide

A detailed guide for the collections library is available at http://docs.scala-lang.org/overviews/collections/introduction.html.

#### Using Collections

It is convienient to treat all collections as either a scala.collection.Traversable or scala.collection.Iterable, as these traits define the vast majority of operations on a collection.

Collections can, of course, be treated as specifically as needed, and the library is designed to ensure that the methods that transform collections will return a collection of the same type:

    scala> val array = Array(1,2,3,4,5,6)
    array: Array[Int] = Array(1, 2, 3, 4, 5, 6)

    scala> array map { _.toString }
    res0: Array[java.lang.String] = Array(1, 2, 3, 4, 5, 6)

    scala> val list = List(1,2,3,4,5,6)
    list: List[Int] = List(1, 2, 3, 4, 5, 6)

    scala> list map { _.toString }
    res1: List[java.lang.String] = List(1, 2, 3, 4, 5, 6)

#### Creating Collections

The most common way to create a collection is to use the companion objects as factories. Of these, the three most common are scala.collection.Seq, scala.collection.immutable.Set, and scala.collection.immutable.Map. Their companion objects are all available as type aliases the either the scala package or in `scala.Predef`, and can be used like so:

    scala> val seq = Seq(1,2,3,4,1)
    seq: Seq[Int] = List(1, 2, 3, 4, 1)

    scala> val set = Set(1,2,3,4,1)
    set: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4)

    scala> val map = Map(1 -> "one",2 -> "two", 3 -> "three",2 -> "too")
    map: scala.collection.immutable.Map[Int,java.lang.String] = Map((1,one), (2,too), (3,three))

It is also typical to use the scala.collection.immutable collections over those in scala.collection.mutable; The types aliased in the `scala.Predef` object are the immutable versions.

Also note that the collections library was carefully designed to include several implementations of each of the three basic collection types. These implementations have specific performance characteristics which are described in the guide.

##### Converting between Java Collections

The `JavaConversions` object provides implicit defs that will allow mostly seamless integration between Java Collections-based APIs and the Scala collections library.

Linear Supertypes
AnyRef, Any
Content Hierarchy Learn more about scaladoc diagrams
Ordering

1. Alphabetic
2. By inheritance

Inherited

1. collection
2. AnyRef
3. Any

1. Hide All
2. Show all

Learn more about member selection
Visibility

1. Public
2. All

### Type Members

1. #### abstract class AbstractIterable[+A] extends AbstractTraversable[A] with Iterable[A]

   Explicit instantiation of the `Iterable` trait to reduce class file size in subclasses.

2. #### abstract class AbstractIterator[+A] extends Iterator[A]

   Explicit instantiation of the `Iterator` trait to reduce class file size in subclasses.

3. #### abstract class AbstractMap[A, +B] extends AbstractIterable[(A, B)] with Map[A, B]

   Explicit instantiation of the `Map` trait to reduce class file size in subclasses.

4. #### abstract class AbstractSeq[+A] extends AbstractIterable[A] with Seq[A]

   Explicit instantiation of the `Seq` trait to reduce class file size in subclasses.

5. #### abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A]

   Explicit instantiation of the `Set` trait to reduce class file size in subclasses.

6. #### abstract class AbstractTraversable[+A] extends Traversable[A]

   Explicit instantiation of the `Traversable` trait to reduce class file size in subclasses.

7. #### trait BitSet extends SortedSet[Int] with BitSetLike[BitSet]

   A common base class for mutable and immutable bitsets.

8. #### trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSetLike[Int, This]

   A template trait for bitsets.

9. #### trait BufferedIterator[+A] extends Iterator[A]

   Buffered iterators are iterators which provide a method `head` that inspects the next element without discarding it.

10. #### trait CustomParallelizable[+A, +ParRepr <: Parallel] extends Parallelizable[A, ParRepr]

11. #### trait DefaultMap[A, +B] extends Map[A, B]

    A default map which implements the `+` and `-` methods of maps.

12. #### trait GenIterable[+A] extends GenIterableLike[A, GenIterable[A]] with GenTraversable[A] with GenericTraversableTemplate[A, GenIterable]

    A trait for all iterable collections which may possibly have their operations implemented in parallel.

13. #### trait GenIterableLike[+A, +Repr] extends GenTraversableLike[A, Repr]

    A template trait for all iterable collections which may possibly have their operations implemented in parallel.

14. #### trait GenMap[A, +B] extends GenMapLike[A, B, GenMap[A, B]] with GenIterable[(A, B)]

    A trait for all traversable collections which may possibly have their operations implemented in parallel.

15. #### trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals with Parallelizable[(A, B), ParMap[A, B]]

    A trait for all maps upon which operations may be implemented in parallel.

16. #### trait GenSeq[+A] extends GenSeqLike[A, GenSeq[A]] with GenIterable[A] with Equals with GenericTraversableTemplate[A, GenSeq]

    A trait for all sequences which may possibly have their operations implemented in parallel.

17. #### trait GenSeqLike[+A, +Repr] extends GenIterableLike[A, Repr] with Equals with Parallelizable[A, ParSeq[A]]

    A template trait for all sequences which may be traversed in parallel.

18. #### trait GenSet[A] extends GenSetLike[A, GenSet[A]] with GenIterable[A] with GenericSetTemplate[A, GenSet]

    A trait for sets which may possibly have their operations implemented in parallel.

19. #### trait GenSetLike[A, +Repr] extends GenIterableLike[A, Repr] with (A) ⇒ Boolean with Equals with Parallelizable[A, ParSet[A]]

    A template trait for sets which may possibly have their operations implemented in parallel.

20. #### trait GenTraversable[+A] extends GenTraversableLike[A, GenTraversable[A]] with GenTraversableOnce[A] with GenericTraversableTemplate[A, GenTraversable]

    A trait for all traversable collections which may possibly have their operations implemented in parallel.

21. #### trait GenTraversableLike[+A, +Repr] extends GenTraversableOnce[A] with Parallelizable[A, ParIterable[A]]

    A template trait for all traversable collections upon which operations may be implemented in parallel.

22. #### trait GenTraversableOnce[+A] extends Any

    A template trait for all traversable-once objects which may be traversed in parallel.

23. #### trait IndexedSeq[+A] extends Seq[A] with GenericTraversableTemplate[A, IndexedSeq] with IndexedSeqLike[A, IndexedSeq[A]]

    A base trait for indexed sequences.

24. #### trait IndexedSeqLike[+A, +Repr] extends SeqLike[A, Repr]

    A template trait for indexed sequences of type `IndexedSeq[A]`.

25. #### trait IndexedSeqOptimized[+A, +Repr] extends IndexedSeqLike[A, Repr]

    A template trait for indexed sequences of type `IndexedSeq[A]` which optimizes the implementation of several methods under the assumption of fast random access.

26. #### trait Iterable[+A] extends Traversable[A] with GenIterable[A] with GenericTraversableTemplate[A, Iterable] with IterableLike[A, Iterable[A]]

    A base trait for iterable collections.

27. #### trait IterableLike[+A, +Repr] extends Equals with TraversableLike[A, Repr] with GenIterableLike[A, Repr]

    A template trait for iterable collections of type `Iterable[A]`.

28. #### trait IterableProxy[+A] extends Iterable[A] with IterableProxyLike[A, Iterable[A]]

    This trait implements a proxy for iterable objects.

29. #### trait IterableView[+A, +Coll] extends IterableViewLike[A, Coll, IterableView[A, Coll]]

    A base trait for non-strict views of `Iterable`s.

30. #### trait IterableViewLike[+A, +Coll, +This <: IterableView[A, Coll] with IterableViewLike[A, Coll, This]] extends Iterable[A] with IterableLike[A, This] with TraversableView[A, Coll] with TraversableViewLike[A, Coll, This]

    A template trait for non-strict views of iterable collections.

31. #### trait Iterator[+A] extends TraversableOnce[A]

    Iterators are data structures that allow to iterate over a sequence of elements.

32. #### trait LinearSeq[+A] extends Seq[A] with GenericTraversableTemplate[A, LinearSeq] with LinearSeqLike[A, LinearSeq[A]]

    A base trait for linear sequences.

33. #### trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr]

    A template trait for linear sequences of type `LinearSeq[A]`.

34. #### trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends LinearSeqLike[A, Repr]

    A template trait for linear sequences of type `LinearSeq[A]` which optimizes the implementation of several methods under the assumption of fast linear access.

35. #### trait Map[A, +B] extends Iterable[(A, B)] with GenMap[A, B] with MapLike[A, B, Map[A, B]]

    A map from keys of type `A` to values of type `B`.

36. #### trait MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]] extends PartialFunction[A, B] with IterableLike[(A, B), This] with GenMapLike[A, B, This] with Subtractable[A, This] with Parallelizable[(A, B), ParMap[A, B]]

    A template trait for maps, which associate keys with values.

37. #### trait MapProxy[A, +B] extends Map[A, B] with MapProxyLike[A, B, Map[A, B]]

    This is a simple wrapper class for scala.collection.Map.

38. #### trait Parallel extends AnyRef

    A marker trait for collections which have their operations parallelised.

39. #### trait Parallelizable[+A, +ParRepr <: Parallel] extends Any

    This trait describes collections which can be turned into parallel collections by invoking the method `par`.

40. #### trait Seq[+A] extends PartialFunction[Int, A] with Iterable[A] with GenSeq[A] with GenericTraversableTemplate[A, Seq] with SeqLike[A, Seq[A]]

    A base trait for sequences.

41. #### trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] with GenSeqLike[A, Repr] with Parallelizable[A, ParSeq[A]]

    A template trait for sequences of type `Seq[A]`

42. #### trait SeqView[+A, +Coll] extends SeqViewLike[A, Coll, SeqView[A, Coll]]

    A base trait for non-strict views of sequences.

43. #### trait SeqViewLike[+A, +Coll, +This <: SeqView[A, Coll] with SeqViewLike[A, Coll, This]] extends Seq[A] with SeqLike[A, This] with IterableView[A, Coll] with IterableViewLike[A, Coll, This]

    A template trait for non-strict views of sequences.

44. #### trait Set[A] extends (A) ⇒ Boolean with Iterable[A] with GenSet[A] with GenericSetTemplate[A, Set] with SetLike[A, Set[A]]

    A base trait for all sets, mutable as well as immutable.

45. #### trait SetLike[A, +This <: SetLike[A, This] with Set[A]] extends IterableLike[A, This] with GenSetLike[A, This] with Subtractable[A, This] with Parallelizable[A, ParSet[A]]

    A template trait for sets.

46. #### trait SetProxy[A] extends Set[A] with SetProxyLike[A, Set[A]]

    This is a simple wrapper class for scala.collection.Set.

47. #### trait SortedMap[A, +B] extends Map[A, B] with SortedMapLike[A, B, SortedMap[A, B]]

    A map whose keys are sorted.

48. #### trait SortedMapLike[A, +B, +This <: SortedMapLike[A, B, This] with SortedMap[A, B]] extends Sorted[A, This] with MapLike[A, B, This]

    A template for maps whose keys are sorted.

49. #### trait SortedSet[A] extends Set[A] with SortedSetLike[A, SortedSet[A]]

    A sorted set.

50. #### trait SortedSetLike[A, +This <: SortedSet[A] with SortedSetLike[A, This]] extends Sorted[A, This] with SetLike[A, This]

    A template for sets which are sorted.

51. #### trait Traversable[+A] extends TraversableLike[A, Traversable[A]] with GenTraversable[A] with TraversableOnce[A] with GenericTraversableTemplate[A, Traversable]

    A trait for traversable collections.

52. #### trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with FilterMonadic[A, Repr] with TraversableOnce[A] with GenTraversableLike[A, Repr] with Parallelizable[A, ParIterable[A]]

    A template trait for traversable collections of type `Traversable[A]`.

53. #### trait TraversableOnce[+A] extends GenTraversableOnce[A]

    A template trait for collections which can be traversed either once only or one or more times.

54. #### trait TraversableProxy[+A] extends Traversable[A] with TraversableProxyLike[A, Traversable[A]]

    This trait implements a proxy for traversable objects.

55. #### trait TraversableView[+A, +Coll] extends TraversableViewLike[A, Coll, TraversableView[A, Coll]]

    A base trait for non-strict views of traversable collections.

56. #### trait TraversableViewLike[+A, +Coll, +This <: TraversableView[A, Coll] with TraversableViewLike[A, Coll, This]] extends Traversable[A] with TraversableLike[A, This] with ViewMkString[A]

    A template trait for non-strict views of traversable collections.

57. #### trait ViewMkString[+A] extends AnyRef

58. #### trait IterableProxyLike[+A, +Repr <: IterableLike[A, Repr] with Iterable[A]] extends IterableLike[A, Repr] with TraversableProxyLike[A, Repr]

    This trait implements a proxy for Iterable objects.

59. #### trait MapProxyLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]] extends MapLike[A, B, This] with IterableProxyLike[(A, B), This]

    This trait implements a proxy for Map objects.

60. #### trait SeqProxy[+A] extends Seq[A] with SeqProxyLike[A, Seq[A]]

    This trait implements a proxy for sequence objects.

61. #### trait SeqProxyLike[+A, +Repr <: SeqLike[A, Repr] with Seq[A]] extends SeqLike[A, Repr] with IterableProxyLike[A, Repr]

    This trait implements a proxy for sequences.

62. #### trait SetProxyLike[A, +This <: SetLike[A, This] with Set[A]] extends SetLike[A, This] with IterableProxyLike[A, This]

    This trait implements a proxy for sets.

63. #### trait TraversableProxyLike[+A, +Repr <: TraversableLike[A, Repr] with Traversable[A]] extends TraversableLike[A, Repr] with Proxy

    This trait implements a proxy for Traversable objects.

### Value Members

1. #### object +:

   An extractor used to head/tail deconstruct sequences.

2. #### object :+

   An extractor used to init/last deconstruct sequences.

3. #### object BitSet extends BitSetFactory[BitSet]

   This object provides a set of operations to create ``BitSet`` values.

4. #### object BitSetLike

   Companion object for BitSets.

5. #### object GenIterable extends GenTraversableFactory[GenIterable]

6. #### object GenMap extends GenMapFactory[GenMap]

7. #### object GenSeq extends GenTraversableFactory[GenSeq]

8. #### object GenSet extends GenTraversableFactory[GenSet]

9. #### object GenTraversable extends GenTraversableFactory[GenTraversable]

10. #### object IndexedSeq extends IndexedSeqFactory[IndexedSeq]

    This object provides a set of operations to create ``IndexedSeq`` values.

11. #### object Iterable extends GenTraversableFactory[Iterable] with TraversableFactory[Iterable]

    This object provides a set of operations to create ``Iterable`` values.

12. #### object IterableView

    An object containing the necessary implicit definitions to make `IterableView`s work.

13. #### object Iterator

    The `Iterator` object provides various functions for creating specialized iterators.

14. #### object JavaConversions extends WrapAsScala with WrapAsJava

    A collection of implicit conversions supporting interoperability between Scala and Java collections.

15. #### object JavaConverters extends DecorateAsJava with DecorateAsScala

    A collection of decorators that allow converting between Scala and Java collections using `asScala` and `asJava` methods.

16. #### object LinearSeq extends SeqFactory[LinearSeq]

    This object provides a set of operations to create ``LinearSeq`` values.

17. #### object Map extends MapFactory[Map]

    This object provides a set of operations needed to create ``Map`` values.

18. #### object Searching

    A collection of wrappers that provide sequence classes with search functionality.

19. #### object Seq extends SeqFactory[Seq]

    This object provides a set of operations to create ``Seq`` values.

20. #### object SeqLike

    The companion object for trait `SeqLike`.

21. #### object SeqView

    An object containing the necessary implicit definitions to make `SeqView`s work.

22. #### object Set extends SetFactory[Set]

    This object provides a set of operations needed to create ``Set`` values.

23. #### object SortedMap extends SortedMapFactory[SortedMap]

24. #### object SortedSet extends SortedSetFactory[SortedSet]

25. #### object Traversable extends GenTraversableFactory[Traversable] with TraversableFactory[Traversable]

    This object provides a set of operations to create `Traversable` values.

26. #### object TraversableOnce

27. #### object TraversableView

    An object containing the necessary implicit definitions to make `TraversableView`s work.

28. #### def breakOut[From, T, To](implicit b: CanBuildFrom[Nothing, T, To]): CanBuildFrom[From, T, To]

    Provides a CanBuildFrom instance that builds a specific target collection (`To') irrespective of the original collection (`From').

29. #### package concurrent

30. #### package convert

31. #### package generic

32. #### package immutable

33. #### package mutable

34. #### package parallel

    Package object for parallel collections.

35. #### package script

### Inherited from AnyRef

### Inherited from Any

### Ungrouped