|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractList
java.util.ArrayList
public class ArrayList
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.
| Constructor Summary | |
|---|---|
ArrayList()
Constructs a new instance of ArrayList with zero capacity. |
|
ArrayList(Collection collection)
Constructs a new instance of ArrayList containing the elements in the specified collection. |
|
ArrayList(int capacity)
Constructs a new instance of ArrayList with the specified capacity. |
|
| Method Summary | |
|---|---|
void |
add(int location,
Object object)
Inserts the specified object into this ArrayList at the specified location. |
boolean |
add(Object object)
Adds the specified object at the end of this ArrayList. |
boolean |
addAll(Collection collection)
Adds the objects in the specified Collection to this ArrayList. |
boolean |
addAll(int location,
Collection collection)
Inserts the objects in the specified Collection at the specified location in 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. |
Object |
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. |
Object |
remove(int location)
Removes the object at the specified location from this ArrayList. |
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. |
Object |
set(int location,
Object 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. |
Object[] |
toArray()
Answers a new array containing all elements contained in this ArrayList. |
Object[] |
toArray(Object[] contents)
Answers an array containing all elements contained in this ArrayList. |
void |
trimToSize()
Sets the capacity of this ArrayList to be the same as the size. |
| Methods inherited from class java.util.AbstractList |
|---|
equals, hashCode, iterator |
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, remove, removeAll, retainAll, toString |
| Methods inherited from class java.lang.Object |
|---|
getClass, println |
| Methods inherited from interface java.util.List |
|---|
containsAll, equals, hashCode, iterator, remove, removeAll, retainAll |
| Constructor Detail |
|---|
public ArrayList()
public ArrayList(int capacity)
capacity - the initial capacity of this ArrayListpublic ArrayList(Collection collection)
collection - the collection of elements to add| Method Detail |
|---|
public void add(int location,
Object object)
add in interface Listadd in class AbstractListlocation - the index at which to insertobject - the object to add
IndexOutOfBoundsException - when location < 0 || >= size()public boolean add(Object object)
add in interface Collectionadd in interface Listadd in class AbstractListobject - the object to add
public boolean addAll(int location,
Collection collection)
addAll in interface ListaddAll in class AbstractListlocation - the index at which to insertcollection - the Collection of objects
IndexOutOfBoundsException - when
location < 0 || > size()public boolean addAll(Collection collection)
addAll in interface CollectionaddAll in interface ListaddAll in class AbstractCollectioncollection - the Collection of objects
public void clear()
clear in interface Collectionclear in interface Listclear in class AbstractListisEmpty(),
size()public Object clone()
clone in class ObjectCloneablepublic boolean contains(Object object)
contains in interface Collectioncontains in interface Listcontains in class AbstractCollectionobject - the object to search for
object is an element of this ArrayList,
false otherwisepublic void ensureCapacity(int minimumCapacity)
minimumCapacity - the minimum number of elements that this ArrayList will hold
before growingpublic Object get(int location)
get in interface Listget in class AbstractListlocation - the index of the element to return
IndexOutOfBoundsException - when location < 0 || >= size()public int indexOf(Object object)
indexOf in interface ListindexOf in class AbstractListobject - the object to search for
public boolean isEmpty()
isEmpty in interface CollectionisEmpty in interface ListisEmpty in class AbstractCollectionsize()public int lastIndexOf(Object object)
lastIndexOf in interface Listobject - the object to search for
public Object remove(int location)
remove in interface Listremove in class AbstractListlocation - the index of the object to remove
IndexOutOfBoundsException - when location < 0 || >= size()
protected void removeRange(int start,
int end)
removeRange in class AbstractListstart - the index at which to start removingend - the index one past the end of the range to remove
IndexOutOfBoundsException - when start < 0, start > end or
end > size()
public Object set(int location,
Object object)
set in interface Listset in class AbstractListlocation - the index at which to put the specified objectobject - the object to add
IndexOutOfBoundsException - when location < 0 || >= size()public int size()
size in interface Collectionsize in interface Listsize in class AbstractCollectionpublic Object[] toArray()
toArray in interface CollectiontoArray in interface ListtoArray in class AbstractCollectionpublic Object[] toArray(Object[] contents)
toArray in interface CollectiontoArray in interface ListtoArray in class AbstractCollectioncontents - the array
ArrayStoreException - when the type of an element in this ArrayList cannot be
stored in the type of the specified arraypublic void trimToSize()
size()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||