java.util
Class ArrayList<E>

java.lang.Object
  extended by java.util.ArrayList<E>
Type Parameters:
E - type of the elements
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, RandomAccess

public class ArrayList<E>
extends Object
implements RandomAccess

An expandable array.

Author:
Andre Nijholt, Sven Köhler

Field Summary
protected  int modCount
           
 
Constructor Summary
ArrayList()
          Create an array list.
ArrayList(Collection<? extends E> c)
           
ArrayList(E[] elements)
          Deprecated. not in JDK
ArrayList(int initialCapacity)
          Create an array list.
 
Method Summary
 boolean add(E element)
          Add a element at the end of the array list.
 void add(int index, E element)
          Add a element at a specific index.
 boolean addAll(Collection<? extends E> c)
           
 void addAll(E[] elements)
          Deprecated. not in JDK
 boolean addAll(int index, Collection<? extends E> c)
           
 void addAll(int index, E[] elements)
          Deprecated. not in JDK
 void clear()
          Clear the array list.
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 void ensureCapacity(int minCapacity)
          Ensure that we have sufficient capacity in the array to store the requested number of elements.
 boolean equals(Object o)
           
 E get(int index)
          Get a specific element.
 int indexOf(Object element)
          Get the first index of a specific element.
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 int lastIndexOf(Object element)
          Get the last index of a specific element.
 ListIterator<E> listIterator()
           
 ListIterator<E> listIterator(int index)
           
 E remove(int index)
          Remove a element at a specific index.
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
protected  void removeRange(int start, int end)
           
 boolean retainAll(Collection<?> c)
           
 E set(int index, E element)
          Replace an element at a specific index with a new element.
 int size()
          Get the number of elements in this array list.
 List<E> subList(int start, int end)
           
 Object[] toArray()
           
<T> T[]
toArray(T[] dest)
           
 void trimToSize()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
containsAll, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Field Detail

modCount

protected transient int modCount
Constructor Detail

ArrayList

public ArrayList()
Create an array list.


ArrayList

public ArrayList(Collection<? extends E> c)

ArrayList

public ArrayList(int initialCapacity)
Create an array list.

Parameters:
initialCapacity - The initial size of the array list.

ArrayList

@Deprecated
public ArrayList(E[] elements)
Deprecated. not in JDK

Create an array list.

Parameters:
elements - The initial elements in the array list.
Method Detail

add

public void add(int index,
                E element)
Add a element at a specific index.

Specified by:
add in interface List<E>
Parameters:
index - The index at which the element should be added.
element - The element to add.

add

public boolean add(E element)
Add a element at the end of the array list.

Specified by:
add in interface Collection<E>
Parameters:
element - The element to add.

addAll

@Deprecated
public void addAll(E[] elements)
Deprecated. not in JDK

Add all elements from the array to the array list.

Parameters:
elements - The array of elements to add.

addAll

@Deprecated
public void addAll(int index,
                              E[] elements)
Deprecated. not in JDK

Add all elements from the array to the array list at a specific index.

Parameters:
index - The index to start adding elements.
elements - The array of elements to add.

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Specified by:
addAll in interface List<E>

clear

public void clear()
Clear the array list.

Specified by:
clear in interface Collection<E>

ensureCapacity

public void ensureCapacity(int minCapacity)
Ensure that we have sufficient capacity in the array to store the requested number of elements. Expand the array if required.

Parameters:
minCapacity -

get

public E get(int index)
Get a specific element.

Specified by:
get in interface List<E>
Parameters:
index - The index of the wanted element.
Returns:
The wanted element.

indexOf

public int indexOf(Object element)
Get the first index of a specific element.

Specified by:
indexOf in interface List<E>
Parameters:
element - The wanted element.
Returns:
The index of the wanted element, or -1 if not found.

lastIndexOf

public int lastIndexOf(Object element)
Get the last index of a specific element.

Specified by:
lastIndexOf in interface List<E>
Parameters:
element - The wanted element.
Returns:
The index of the wanted element, or -1 if not found.

remove

public E remove(int index)
Remove a element at a specific index.

Specified by:
remove in interface List<E>
Parameters:
index - The index of the element to remove.
Returns:
the removed element.

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>

removeRange

protected void removeRange(int start,
                           int end)

set

public E set(int index,
             E element)
Replace an element at a specific index with a new element.

Specified by:
set in interface List<E>
Parameters:
index - The index of the element to set.
element - The new element.
Returns:
the old element.

size

public int size()
Get the number of elements in this array list.

Specified by:
size in interface Collection<E>
Returns:
the number of elements.

listIterator

public ListIterator<E> listIterator(int index)
Specified by:
listIterator in interface List<E>

subList

public List<E> subList(int start,
                       int end)
Specified by:
subList in interface List<E>

trimToSize

public void trimToSize()

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<E>
Overrides:
equals in class Object

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>

listIterator

public ListIterator<E> listIterator()
Specified by:
listIterator in interface List<E>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<E>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<E>

toArray

public <T> T[] toArray(T[] dest)
Specified by:
toArray in interface Collection<E>