public class ArrayList4D<E>
extends java.util.AbstractList<E>
implements java.util.List<E>, java.util.RandomAccess, java.lang.Cloneable
Each list has a capacity, and as the array reaches that capacity it is automatically transferred to a larger array. You also have access to ensureCapacity and trimToSize to control the backing array's size, avoiding reallocation or wasted memory.
ArrayList is not synchronized, so if you need multi-threaded access,
consider using:
List l = Collections.synchronizedList(new ArrayList(...));
The iterators are fail-fast, meaning that any structural
modification, except for remove()
called on the iterator
itself, cause the iterator to throw a
ConcurrentModificationException
rather than exhibit
non-deterministic behavior.
Collection
,
List
,
LinkedList
,
Vector
,
Collections.synchronizedList(List)
,
AbstractList
Constructor and Description |
---|
ArrayList4D()
Construct a new ArrayList with the default capacity (16).
|
ArrayList4D(java.util.Collection<? extends E> c)
Construct a new ArrayList, and initialize it with the elements
in the supplied Collection.
|
ArrayList4D(int capacity)
Construct a new ArrayList with the supplied initial capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
Appends the supplied element to the end of this list.
|
void |
add(int index,
E e)
Adds the supplied element at the specified index, shifting all
elements currently at that index or higher one to the right.
|
boolean |
addAll(java.util.Collection<? extends E> c)
Add each element in the supplied Collection to this List.
|
boolean |
addAll(int index,
java.util.Collection<? extends E> c)
Add all elements in the supplied collection, inserting them beginning
at the specified index.
|
void |
clear()
Removes all elements from this List
|
java.lang.Object |
clone()
Creates a shallow copy of this ArrayList (elements are not cloned).
|
boolean |
contains(java.lang.Object e)
Returns true iff element is in this ArrayList.
|
void |
ensureCapacity(int minCapacity)
Guarantees that this list will have at least enough capacity to
hold minCapacity elements.
|
E |
get(int index)
Retrieves the element at the user-supplied index.
|
int |
indexOf(java.lang.Object e)
Returns the lowest index at which element appears in this List, or
-1 if it does not appear.
|
boolean |
isEmpty()
Checks if the list is empty.
|
int |
lastIndexOf(java.lang.Object e)
Returns the highest index at which element appears in this List, or
-1 if it does not appear.
|
E |
remove(int index)
Removes the element at the user-supplied index.
|
protected void |
removeRange(int fromIndex,
int toIndex)
Removes all elements in the half-open interval [fromIndex, toIndex).
|
E |
set(int index,
E e)
Sets the element at the specified index.
|
int |
size()
Returns the number of elements in this list.
|
void |
sort(java.util.Comparator<? super E> c) |
java.lang.Object[] |
toArray()
Returns an Object array containing all of the elements in this ArrayList.
|
<T> T[] |
toArray(T[] a)
Returns an Array whose component type is the runtime component type of
the passed-in Array.
|
void |
trimToSize()
Trims the capacity of this List to be equal to its size;
a memory saver.
|
equals, hashCode, iterator, listIterator, listIterator, subList
containsAll, remove, removeAll, retainAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
public ArrayList4D(int capacity)
capacity
- initial capacity of this ArrayListjava.lang.IllegalArgumentException
- if capacity is negativepublic ArrayList4D()
public ArrayList4D(java.util.Collection<? extends E> c)
c
- the collection whose elements will initialize this listjava.lang.NullPointerException
- if c is nullpublic void trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity
- the minimum guaranteed capacitypublic int size()
public boolean isEmpty()
public boolean contains(java.lang.Object e)
public int indexOf(java.lang.Object e)
public int lastIndexOf(java.lang.Object e)
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E>
toArray
in interface java.util.List<E>
toArray
in class java.util.AbstractCollection<E>
a
- the passed-in Arrayjava.lang.ArrayStoreException
- if the runtime type of a does not allow
an element in this listjava.lang.NullPointerException
- if a is nullpublic E get(int index)
public E set(int index, E e)
set
in interface java.util.List<E>
set
in class java.util.AbstractList<E>
index
- the index at which the element is being sete
- the element to be setjava.lang.IndexOutOfBoundsException
- if index < 0 || index >= 0public boolean add(E e)
public void add(int index, E e)
public E remove(int index)
public void clear()
public boolean addAll(java.util.Collection<? extends E> c)
addAll
in interface java.util.Collection<E>
addAll
in interface java.util.List<E>
addAll
in class java.util.AbstractCollection<E>
c
- a Collection containing elements to be added to this Listjava.lang.NullPointerException
- if c is nullpublic boolean addAll(int index, java.util.Collection<? extends E> c)
addAll
in interface java.util.List<E>
addAll
in class java.util.AbstractList<E>
index
- the index at which the elements will be insertedc
- the Collection containing the elements to be insertedjava.lang.IndexOutOfBoundsException
- if index < 0 || index > 0java.lang.NullPointerException
- if c is nullprotected void removeRange(int fromIndex, int toIndex)
removeRange
in class java.util.AbstractList<E>
fromIndex
- the first index which will be removedtoIndex
- one greater than the last index which will be removedjava.lang.IndexOutOfBoundsException
- if fromIndex > toIndex