Class ArrayList<E>
- java.lang.Object
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractIterable<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractList<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractIndexedList<E>
-
- com.github.andrewoma.dexx.collection.ArrayList<E>
-
- All Implemented Interfaces:
IndexedList<E>
,Iterable<E>
,List<E>
,Traversable<E>
,java.lang.Iterable<E>
public class ArrayList<E> extends AbstractIndexedList<E>
ArrayList
is anIndexedList
implementation backed by an array.WARNING: All modifications copy the entire backing array.
ArrayLists
should only be used where modifications are infrequent and access times are critical. ArrayList is also compact in memory usage, so may be appropriate for small lists. If there is any doubt regarding access patterns for aList
then use aVector
instead.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull ArrayList<E>
append(E elem)
Returns a list with the specified element appended to the bottom of the list.@NotNull ArrayList<E>
drop(int number)
Returns a list containing all elements in this list, excluding the firstnumber
of elements.static <E> ArrayList<E>
empty()
static <E> @NotNull BuilderFactory<E,ArrayList<E>>
factory()
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).boolean
isEmpty()
Returns true if this collection is empty.@NotNull java.util.Iterator<E>
iterator()
E
last()
Returns last element in the list ornull
if the list is empty.@NotNull ArrayList<E>
prepend(E elem)
Returns a list with the specified element prepended to the top of the list.@NotNull ArrayList<E>
range(int from, boolean fromInclusive, int to, boolean toInclusive)
Returns a list containing a contiguous range of elements from this list.@NotNull ArrayList<E>
set(int i, E elem)
Returns a list with the element set to the value specified at the index (zero-based).int
size()
Returns the size of the collection.@NotNull List<E>
tail()
Returns a list containing all elements in the list, excluding the first element.@NotNull ArrayList<E>
take(int number)
Returns a list containing the firstnumber
of elements from this list.-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractList
asList, equals, hashCode, indexOf, lastIndexOf
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractIterable
forEach
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable
makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.andrewoma.dexx.collection.List
asList, indexOf, lastIndexOf
-
Methods inherited from interface com.github.andrewoma.dexx.collection.Traversable
forEach, makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet
-
-
-
-
Field Detail
-
EMPTY
private static final ArrayList<java.lang.Object> EMPTY
-
elements
private final java.lang.Object[] elements
-
-
Method Detail
-
empty
public static <E> ArrayList<E> empty()
-
factory
@NotNull public static <E> @NotNull BuilderFactory<E,ArrayList<E>> factory()
-
set
@NotNull public @NotNull ArrayList<E> set(int i, E elem)
Description copied from interface:List
Returns a list with the element set to the value specified at the index (zero-based).
-
append
@NotNull public @NotNull ArrayList<E> append(E elem)
Description copied from interface:List
Returns a list with the specified element appended to the bottom of the list.
-
prepend
@NotNull public @NotNull ArrayList<E> prepend(E elem)
Description copied from interface:List
Returns a list with the specified element prepended to the top of the list.
-
drop
@NotNull public @NotNull ArrayList<E> drop(int number)
Description copied from interface:List
Returns a list containing all elements in this list, excluding the firstnumber
of elements.
-
take
@NotNull public @NotNull ArrayList<E> take(int number)
Description copied from interface:List
Returns a list containing the firstnumber
of elements from this list.
-
range
@NotNull public @NotNull ArrayList<E> range(int from, boolean fromInclusive, int to, boolean toInclusive)
Description copied from interface:List
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
-
get
public E get(int i)
Description copied from interface:List
Returns the element at the specified index in this list (zero-based).
-
first
@Nullable public E first()
Description copied from interface:List
Returns first element in the list ornull
if the list is empty.
-
last
@Nullable public E last()
Description copied from interface:List
Returns last element in the list ornull
if the list is empty.
-
tail
@NotNull public @NotNull List<E> tail()
Description copied from interface:List
Returns a list containing all elements in the list, excluding the first element. An empty list is returned if the list is empty.
-
iterator
@NotNull public @NotNull java.util.Iterator<E> iterator()
-
size
public int size()
Description copied from interface:Traversable
Returns the size of the collection.Warning: infinite collections are possible, as are collections that require traversal to calculate the size.
- Specified by:
size
in interfaceTraversable<E>
- Overrides:
size
in classAbstractTraversable<E>
-
isEmpty
public boolean isEmpty()
Description copied from interface:Traversable
Returns true if this collection is empty.- Specified by:
isEmpty
in interfaceTraversable<E>
- Overrides:
isEmpty
in classAbstractTraversable<E>
-
-