Interface List<E>
-
- All Superinterfaces:
Iterable<E>
,java.lang.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:IndexedList
: Guarantees fast random access to elements in theList
via indexes.LinkedList
: Guarantees fastprepend(Object)
andtail()
operations.
The performance of other operations is unspecified - care must be taken to use specific implementations using the appropriate access patterns.
-
-
Method Summary
All Methods Instance Methods Abstract Methods 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.java.util.List<E>
asList()
Returns an immutable view of this list as an instance ofjava.util.List
.@NotNull List<E>
drop(int number)
Returns a list containing all elements in this list, excluding the firstnumber
of elements.E
first()
Returns first element in the list ornull
if the list is empty.E
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.E
last()
Returns last element in the list ornull
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>
tail()
Returns a list containing all elements in the list, excluding the first element.@NotNull List<E>
take(int number)
Returns a list containing the firstnumber
of elements from this list.-
Methods inherited from interface com.github.andrewoma.dexx.collection.Traversable
forEach, isEmpty, makeString, makeString, size, to, toArray, toArray, toIndexedList, toSet, toSortedSet
-
-
-
-
Method Detail
-
get
E get(int i)
Returns the element at the specified index in this list (zero-based).- Throws:
java.lang.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:
java.lang.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 ornull
if the list is empty.
-
last
@Nullable E last()
Returns last element in the list ornull
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 firstnumber
of elements.
-
take
@NotNull @NotNull List<E> take(int number)
Returns a list containing the firstnumber
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 thefrom
index will be includedto
- end index for the range (zero-based)toInclusive
- if true, the element at theto
index will be included
-
asList
@NotNull java.util.List<E> asList()
Returns an immutable view of this list as an instance ofjava.util.List
.
-
-