Interface ImmutableCollection<E extends @Nullable Object>

Type Parameters:
E - the type of elements contained in the collection. The immutable collection is covariant on its element type.
All Superinterfaces:
Iterable<E>
All Known Subinterfaces:
ImmutableList<E>, ImmutableSet<E>, PersistentCollection<E>, PersistentList<E>, PersistentSet<E>
All Known Implementing Classes:
ImmutableList.SubList

public interface ImmutableCollection<E extends @Nullable Object> extends Iterable<E>

A generic immutable collection of elements. Methods in this interface support only read-only access to the collection.

Modification operations are supported through the PersistentCollection interface.

Implementors of this interface take responsibility to be immutable. Once constructed they must contain the same elements in the same order.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(E element)
    Returns true if this collection contains the specified element.
    boolean
    containsAll(Collection<? extends E> elements)
    Returns true if this collection contains all elements in the specified collection.
    default boolean
    Returns true if this collection contains no elements.
    Returns an iterator over the elements of this collection.
    default Stream<E>
    Returns a possibly parallel Stream with this collection as its source.
    int
    Returns the number of elements in this collection.
    default Stream<E>
    Returns a sequential Stream with this collection as its source.

    Methods inherited from interface Iterable

    forEach, spliterator
  • Method Details

    • size

      int size()
      Returns the number of elements in this collection.
    • isEmpty

      default boolean isEmpty()
      Returns true if this collection contains no elements.
    • contains

      boolean contains(E element)

      Returns true if this collection contains the specified element.

      More formally, returns true if and only if this collection contains at least one element e such that Objects.equals(o, e).

    • containsAll

      boolean containsAll(Collection<? extends E> elements)
      Returns true if this collection contains all elements in the specified collection.
    • iterator

      Iterator<E> iterator()
      Returns an iterator over the elements of this collection.
      Specified by:
      iterator in interface Iterable<E extends @Nullable Object>
    • stream

      default Stream<E> stream()
      Returns a sequential Stream with this collection as its source.
    • parallelStream

      default Stream<E> parallelStream()
      Returns a possibly parallel Stream with this collection as its source.