|
APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectap.java.util.ArrayList
Resizable array-like collection that implements the
List
interface. Note: for the APCS A course
students do not need to know that ArrayList
implements the List
interface. In the A course,
the ArrayList
class is a growable array that stores
objects (not primitive types). The first valid
position for an ArrayList
object list
is the index zero/0,
the last valid position is list.size()-1
.
The methods size
, iterator
listIterator
, get
and set
methods run in constant time (that is the time it takes them to
execute is independent of the number of items stored in the
ArrayList
.) The single-parameter
method add
runs
in amortized constant time. This means it takes
O(n) time to add n elements. The method remove
and the two-parameter method add
.
run in linear time since they both require shifting elements.
Constructor Summary | |
ArrayList()
Constructs an empty ArrayList . |
Method Summary | |
void |
add(int index,
java.lang.Object o)
Inserts the argument at the specified position in this list. |
boolean |
add(java.lang.Object o)
Append (adds) the argument to the end of this ArrayList . |
java.lang.Object |
get(int index)
Returns the element at the specified position in this list. |
Iterator |
iterator()
Returns an iterator over the elements in this list (AB only). |
ListIterator |
listIterator()
Returns a list iterator over the elements in this list (AB only). |
java.lang.Object |
remove(int index)
Removes the element at the specified position from this list. |
java.lang.Object |
set(int index,
java.lang.Object o)
Replaces the element at the specified position in this list with the specified object. |
int |
size()
Returns the number of elements in this list. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Collection |
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray |
Constructor Detail |
public ArrayList()
ArrayList
.
Method Detail |
public boolean add(java.lang.Object o)
ArrayList
.
add
in interface List
o
- is the element appended to this list.
public void add(int index, java.lang.Object o)
index
- is the position at which the new element is addedo
- is the new element added to this list
java.lang.IndexOutOfBoundsException
- if 0 < index || index >=
size()
public int size()
size
in interface List
public Iterator iterator()
next()
, first the element with index 0 and last
the element with index size()-1
.
iterator
in interface List
public ListIterator listIterator()
next()
first the element with index 0 and last
the element with index size()-1
.
listIterator
in interface List
public java.lang.Object get(int index)
get
in interface List
index
- is the position of the element returned
java.lang.IndexOutOfBoundsException
- if 0 < index || index >=
size()
public java.lang.Object set(int index, java.lang.Object o)
set
in interface List
index
- is the position of the element that will be
replacedo
- is the object to be stored at the specified position
java.lang.IndexOutOfBoundsException
- if 0 < index || index >=
size()
public java.lang.Object remove(int index)
index
- is the position of the element removed
java.lang.IndexOutOfBoundsException
- if 0 < index || index >=
size()
|
unofficial documentation for the APCS Java Subset | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |