Package com.github.andrewoma.dexx.collection

Dexx collections are a port of Scala's immutable, persistent collection classes to pure Java.

Persistent in the context of functional data structures means the data structure preserves the previous version of itself when modified. This means any reference to a collection is effectively immutable. However, modifications can be made by returning a new version of the data structure, leaving the original structure unchanged.

The following diagram shows the key interfaces (blue) and classes (green) in this package:

Dexx collections overview

Usage Notes:

  • Each of the collection types has an associated companion class (plural form) that is the preferred method of construction. e.g. To create a Set, use the Sets class.

  • Many of the collections have the same name as their mutable java.util counterparts, however they are not directly related. This is due to the interfaces being fundamentally incompatible as operations the "modify" collections must return a new instance for persistent collections.

  • Collections can be viewed as their java.util counterpart by using as...() methods. e.g. Set.asSet(). Such views are immutable.

  • Collections can be constructed from java.util collections by using the copyOf(...) methods in the companion classes. e.g. Sets.copyOf(java.lang.Iterable).

  • While operations on collections often return a new instance that reflects the modifications, this is not a guarantee. e.g. Attempting to remove an element from a Set that does not exist may return the same collection as no modifications were required.

See the project site for further examples and information.