Reference:Java.util.ArrayList
From Triled Wiki
java.util
public class java.util.ArrayList
| java.lang.Object | ||||
| java.util.AbstractCollection | Collection | |||
| java.util.AbstractList | List | |||
| java.util.ArrayList | Serializable Cloneable List RandomAccess | |||
ArrayList is an implementation of List, backed by an array. All optional operations are supported, adding, removing, and replacing. The elements can be any objects.
[edit] Summary
[edit] Fields inherited from class java.util.AbstractList
[edit] Public Constructors
| ArrayList () | |||||
| Constructs a new instance of ArrayList with zero capacity. | |||||
| ArrayList (int capacity) | |||||
| Constructs a new instance of ArrayList with the specified capacity. | |||||
| )">ArrayList (Collection collection) | |||||
| Constructs a new instance of ArrayList containing the elements in the specified collection. | |||||
[edit] Public Methods
| void | add (int location, E object) | ||||
| Inserts the specified object into this ArrayList at the specified location. | |||||
| boolean | add (E object) | ||||
| Adds the specified object at the end of this ArrayList. | |||||
| boolean | )">addAll (int location, Collection collection) | ||||
| Inserts the objects in the specified Collection at the specified location in this ArrayList. | |||||
| boolean | )">addAll (Collection collection) | ||||
| Adds the objects in the specified Collection to this ArrayList. | |||||
| void | clear () | ||||
| Removes all elements from this ArrayList, leaving it empty. | |||||
| Object | clone () | ||||
| Answers a new ArrayList with the same elements, size and capacity as this ArrayList. | |||||
| boolean | contains (Object object) | ||||
| Searches this ArrayList for the specified object. | |||||
| void | ensureCapacity (int minimumCapacity) | ||||
| Ensures that this ArrayList can hold the specified number of elements without growing. | |||||
| E | get (int location) | ||||
| Answers the element at the specified location in this ArrayList. | |||||
| int | indexOf (Object object) | ||||
| Searches this ArrayList for the specified object and returns the index of the first occurrence. | |||||
| boolean | isEmpty () | ||||
| Answers if this ArrayList has no elements, a size of zero. | |||||
| int | lastIndexOf (Object object) | ||||
| Searches this ArrayList for the specified object and returns the index of the last occurrence. | |||||
| E | remove (int location) | ||||
| Removes the object at the specified location from this ArrayList. | |||||
| E | set (int location, E object) | ||||
| Replaces the element at the specified location in this ArrayList with the specified object. | |||||
| int | size () | ||||
| Answers the number of elements in this ArrayList. | |||||
| T[ ] | toArray (T[ ] contents) | ||||
| Answers an array containing all elements contained in this ArrayList. | |||||
| Object[ ] | toArray () | ||||
| Answers a new array containing all elements contained in this ArrayList. | |||||
| void | trimToSize () | ||||
| Sets the capacity of this ArrayList to be the same as the size. | |||||
[edit] Protected Methods
| void | removeRange (int start, int end) | ||||
| Removes the objects in the specified range from the start to the end, but not including the end index. | |||||
[edit] Methods inherited from class java.util.AbstractList
add, add, )">addAll, clear, equals, get, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList[edit] Methods inherited from class java.util.AbstractCollection
add, )">addAll, clear, contains, )">containsAll, isEmpty, iterator, remove, )">removeAll, )">retainAll, size, toArray, toArray, toString[edit] Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait[edit] Methods inherited from interface java.util.List
add, add, )">addAll, )">addAll, clear, contains, )">containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, )">removeAll, )">retainAll, set, size, subList, toArray, toArray[edit] Methods inherited from interface java.util.Collection
add, )">addAll, clear, contains, )">containsAll, equals, hashCode, isEmpty, iterator, remove, )">removeAll, )">retainAll, size, toArray, toArray[edit] Methods inherited from interface java.lang.Iterable
[edit] Details
[edit] Public Constructors
[edit] public ArrayList()
Constructs a new instance of ArrayList with zero capacity.
[edit] public ArrayList(int capacity)
Constructs a new instance of ArrayList with the specified capacity.
Parameters
| capacity | the initial capacity of this ArrayList |
|---|
[edit] public ArrayList(Collection collection)
Constructs a new instance of ArrayList containing the elements in the specified collection. The ArrayList will have an initial capacity which is 110% of the size of the collection. The order of the elements in this ArrayList is the order they are returned by the collection iterator.
Parameters
| collection | the collection of elements to add |
|---|
[edit] Public Methods
[edit] public void add(int location, E object)
Inserts the specified object into this ArrayList at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this ArrayList, the object is added at the end.
Parameters
| location | the index at which to insert |
|---|---|
| object | the object to add |
Throws
| IndexOutOfBoundsException | when location < 0 | >= size() |
|---|
[edit] public boolean add(E object)
Adds the specified object at the end of this ArrayList.
Parameters
| object | the object to add |
|---|
Returns
- true
[edit] public boolean addAll(int location, Collection collection)
Inserts the objects in the specified Collection at the specified location in this ArrayList. The objects are added in the order they are returned from the Collection iterator.
Parameters
| location | the index at which to insert |
|---|---|
| collection | the Collection of objects |
Returns
- true if this ArrayList is modified, false otherwise
Throws
| IndexOutOfBoundsException | when location < 0 | > size() |
|---|
[edit] public boolean addAll(Collection collection)
Adds the objects in the specified Collection to this ArrayList.
Parameters
| collection | the Collection of objects |
|---|
Returns
- true if this ArrayList is modified, false otherwise
[edit] public void clear()
Removes all elements from this ArrayList, leaving it empty.
See Also
[edit] public Object clone()
Answers a new ArrayList with the same elements, size and capacity as this ArrayList.
Returns
- a shallow copy of this ArrayList
See Also
[edit] public boolean contains(Object object)
Searches this ArrayList for the specified object.
Parameters
| object | the object to search for |
|---|
Returns
- true if object is an element of this ArrayList, false otherwise
[edit] public void ensureCapacity(int minimumCapacity)
Ensures that this ArrayList can hold the specified number of elements without growing.
Parameters
| minimumCapacity | the minimum number of elements that this ArrayList will hold before growing |
|---|
[edit] public E get(int location)
Answers the element at the specified location in this ArrayList.
Parameters
| location | the index of the element to return |
|---|
Returns
- the element at the specified index
Throws
| IndexOutOfBoundsException | when location < 0 | >= size() |
|---|
[edit] public int indexOf(Object object)
Searches this ArrayList for the specified object and returns the index of the first occurrence.
Parameters
| object | the object to search for |
|---|
Returns
- the index of the first occurrence of the object
[edit] public boolean isEmpty()
Answers if this ArrayList has no elements, a size of zero.
Returns
- true if this ArrayList has no elements, false otherwise
See Also
[edit] public int lastIndexOf(Object object)
Searches this ArrayList for the specified object and returns the index of the last occurrence.
Parameters
| object | the object to search for |
|---|
Returns
- the index of the last occurrence of the object
[edit] public E remove(int location)
Removes the object at the specified location from this ArrayList.
Parameters
| location | the index of the object to remove |
|---|
Returns
- the removed object
Throws
| IndexOutOfBoundsException | when location < 0 | >= size() |
|---|
[edit] public E set(int location, E object)
Replaces the element at the specified location in this ArrayList with the specified object.
Parameters
| location | the index at which to put the specified object |
|---|---|
| object | the object to add |
Returns
- the previous element at the index
Throws
| IndexOutOfBoundsException | when location < 0 | >= size() |
|---|
[edit] public int size()
Answers the number of elements in this ArrayList.
Returns
- the number of elements in this ArrayList
[edit] public T[ ]toArray(T[ ] contents)
Answers an array containing all elements contained in this ArrayList. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than this ArrayList, the array element following the collection elements is set to null.
Parameters
| contents | the array |
|---|
Returns
- an array of the elements from this ArrayList
Throws
| ArrayStoreException | when the type of an element in this ArrayList cannot be stored in the type of the specified array |
|---|
[edit] public Object[ ]toArray()
Answers a new array containing all elements contained in this ArrayList.
Returns
- an array of the elements from this ArrayList
[edit] public void trimToSize()
Sets the capacity of this ArrayList to be the same as the size.
See Also
[edit] Protected Methods
[edit] protected void removeRange(int start, int end)
Removes the objects in the specified range from the start to the end, but not including the end index.
Parameters
| start | the index at which to start removing |
|---|---|
| end | the index one past the end of the range to remove |
Throws
| IndexOutOfBoundsException | when start < 0, start > end or end > size() |
|---|
[edit] References
- Original documentation page for Android SDK build m5-rc15e - 14 apr 2008 17:27
