Interface List<E>

All Superinterfaces:
Iterable<E>, Iterable<E>, Traversable<E>
All Known Subinterfaces:
IndexedList<E>, LinkedList<E>
All Known Implementing Classes:
AbstractIndexedList, AbstractLinkedList, AbstractList, ArrayList, Cons, ConsList, Nil, Vector

public interface List<E> extends Iterable<E>
List defines an sequence of elements where the order is preserved.

There are two sub-interfaces of List that define very different performance characteristics:

The performance of other operations is unspecified - care must be taken to use specific implementations using the appropriate access patterns.

  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull List<E>
    append(E elem)
    Returns a list with the specified element appended to the bottom of the list.
    Returns an immutable view of this list as an instance of java.util.List.
    @NotNull List<E>
    drop(int number)
    Returns a list containing all elements in this list, excluding the first number of elements.
    Returns first element in the list or null if the list is empty.
    get(int i)
    Returns the element at the specified index in this list (zero-based).
    int
    indexOf(E elem)
    Returns the index of the first occurrence of the specified element in the list or -1 if there are no occurrences.
    Returns last element in the list or null if the list is empty.
    int
    lastIndexOf(E elem)
    Returns the index of the last occurrence of the specified element in the list or -1 if there are no occurrences.
    @NotNull List<E>
    prepend(E elem)
    Returns a list with the specified element prepended to the top of the list.
    @NotNull List<E>
    range(int from, boolean fromInclusive, int to, boolean toInclusive)
    Returns a list containing a contiguous range of elements from this list.
    @NotNull List<E>
    set(int i, E elem)
    Returns a list with the element set to the value specified at the index (zero-based).
    @NotNull List<E>
    Returns a list containing all elements in the list, excluding the first element.
    @NotNull List<E>
    take(int number)
    Returns a list containing the first number of elements from this list.

    Methods inherited from interface com.github.andrewoma.dexx.collection.Iterable

    iterator

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface com.github.andrewoma.dexx.collection.Traversable

    forEach, isEmpty, makeString, makeString, size, to, toArray, toArray, toIndexedList, toSet, toSortedSet
  • Method Details

    • get

      E get(int i)
      Returns the element at the specified index in this list (zero-based).
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • set

      @NotNull @NotNull List<E> set(int i, E elem)
      Returns a list with the element set to the value specified at the index (zero-based).
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • append

      @NotNull @NotNull List<E> append(E elem)
      Returns a list with the specified element appended to the bottom of the list.
    • prepend

      @NotNull @NotNull List<E> prepend(E elem)
      Returns a list with the specified element prepended to the top of the list.
    • indexOf

      int indexOf(E elem)
      Returns the index of the first occurrence of the specified element in the list or -1 if there are no occurrences.
    • lastIndexOf

      int lastIndexOf(E elem)
      Returns the index of the last occurrence of the specified element in the list or -1 if there are no occurrences.
    • first

      @Nullable E first()
      Returns first element in the list or null if the list is empty.
    • last

      @Nullable E last()
      Returns last element in the list or null if the list is empty.
    • tail

      @NotNull @NotNull List<E> tail()
      Returns a list containing all elements in the list, excluding the first element. An empty list is returned if the list is empty.
    • drop

      @NotNull @NotNull List<E> drop(int number)
      Returns a list containing all elements in this list, excluding the first number of elements.
    • take

      @NotNull @NotNull List<E> take(int number)
      Returns a list containing the first number of elements from this list.
    • range

      @NotNull @NotNull List<E> range(int from, boolean fromInclusive, int to, boolean toInclusive)
      Returns a list containing a contiguous range of elements from this list.
      Parameters:
      from - starting index for the range (zero-based)
      fromInclusive - if true, the element at the from index will be included
      to - end index for the range (zero-based)
      toInclusive - if true, the element at the to index will be included
    • asList

      @NotNull List<E> asList()
      Returns an immutable view of this list as an instance of java.util.List.