Class BasicArrayList

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--BasicArrayList
All Implemented Interfaces:
Collection, List

public class BasicArrayList
extends AbstractList

BasicArrayList.java
Illustrates the implementation of several of the ArrayList methods.

Created: Wed Feb 19 11:24:05 2003

Author:
Stuart C. Shapiro
Documentation from Java API

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
BasicArrayList()
          Constructs an empty list with an initial capacity of ten.
BasicArrayList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 boolean add(Object o)
          Appends the specified element to the end of this list.
 Object get(int index)
          Returns the element at the specified position in this list.
 Object remove(int index)
          Removes the element at the specified position in this list.
 int size()
          Returns the number of elements in this list.
 String toString()
          Returns a string representation of this list.
 
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

BasicArrayList

public BasicArrayList(int initialCapacity)
               throws IllegalArgumentException
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.
Throws:
IllegalArgumentException - if the specified initial capacity is negative

BasicArrayList

public BasicArrayList()
Constructs an empty list with an initial capacity of ten.

Method Detail

get

public Object get(int index)
           throws IndexOutOfBoundsException
Returns the element at the specified position in this list.

Specified by:
get in interface List
Specified by:
get in class AbstractList
Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

size

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

Specified by:
size in interface List
Specified by:
size in class AbstractCollection
Returns:
the number of elements in this list.

add

public boolean add(Object o)
Appends the specified element to the end of this list.

Specified by:
add in interface List
Overrides:
add in class AbstractList
Parameters:
o - element to be appended to this list.
Returns:
true (as per the general contract of Collection.add).

remove

public Object remove(int index)
              throws IndexOutOfBoundsException
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).

Specified by:
remove in interface List
Overrides:
remove in class AbstractList
Parameters:
index - the index of the element to removed.
Returns:
the element that was removed from the list.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

toString

public String toString()
Returns a string representation of this list.

Overrides:
toString in class AbstractCollection
Returns:
a string representation of this list.