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
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
Modifier and TypeMethodDescriptionReturns a list with the specified element appended to the bottom of the list.asList()
Returns an immutable view of this list as an instance ofjava.util.List
.drop
(int number) Returns a list containing all elements in this list, excluding the firstnumber
of elements.first()
Returns first element in the list ornull
if the list is empty.get
(int i) Returns the element at the specified index in this list (zero-based).int
Returns the index of the first occurrence of the specified element in the list or -1 if there are no occurrences.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.Returns a list with the specified element prepended to the top of the list.range
(int from, boolean fromInclusive, int to, boolean toInclusive) Returns a list containing a contiguous range of elements from this list.Returns a list with the element set to the value specified at the index (zero-based).tail()
Returns a list containing all elements in the list, excluding the first element.take
(int number) Returns a list containing the firstnumber
of elements from this list.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
Returns the element at the specified index in this list (zero-based).- Throws:
IndexOutOfBoundsException
- if the index is out of range
-
set
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
Returns a list with the specified element appended to the bottom of the list. -
prepend
Returns a list with the specified element prepended to the top of the list. -
indexOf
Returns the index of the first occurrence of the specified element in the list or -1 if there are no occurrences. -
lastIndexOf
Returns the index of the last occurrence of the specified element in the list or -1 if there are no occurrences. -
first
Returns first element in the list ornull
if the list is empty. -
last
Returns last element in the list ornull
if the list is empty. -
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
Returns a list containing all elements in this list, excluding the firstnumber
of elements. -
take
Returns a list containing the firstnumber
of elements from this list. -
range
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
Returns an immutable view of this list as an instance ofjava.util.List
.
-