RetroArrayList

 

RetroArrayList.java provides a 1.1 version of ArrayList it implements some of the Java 1.2 List interface

 

 

public RetroArrayList()

Default constructor

Postcondition: Empty list is constructed.

 

public RetroArrayList(int initialSize)

Specific constructor

Postcondition: Empty list is constructed with capacity of initialSize.

 

public void add(int index, Object element)

Add an element to the list at a given position.

Precondition: the position is valid.

Postcondition: object has been inserted in the correct position.

 

public boolean add(Object o)

Add an element to the list.

Postcondition: object has been added to the end of the list.

Return: true if the add was successful.

 

public void clear()

Clear the list.

Postcondition: the list is empty.

 

public Object clone ()

Make a shallow copy of the list.

Return: a clone of the list.

 

public boolean contains(Object elem)

Does the list contain the element.

Return: a true if and only if elem is in the list.

 

public int indexOf(Object elem)

What is the position of the first occurrence of an element in the list.

Return: if elem is in the list return its first position, otherwise return -1.

 

public int lastIndexOf(Object elem)

What is the position of the last occurrence of an element in the list.

Return: if elem is in the list return its last position, otherwise return -1.

 

public void trimToSize()

Reduce the size of the array holding the list.

Postcondition: the array holding the list has no unused spaces.

 

public void ensureCapacity(int minCapacity)

Mutator to make sure that the capacity of the array being used for storage is of a minimum size.

Postcondition: if the array is too small, a larger array has been allocated and the elements have been copied over.

 

public int size()

Size accessor

Return: number of elements in the list

 

public boolean isEmpty()

Check if list is empty

Return: true if list is empty, and false otherwise

 

public Object get(int index)

Get an object at a given location.

Precondition: the index is valid.

Return: the element at the given index.

 

public Object set(int index, Object element)

Change the object at a given location.

Precondition: the index is valid.

Precondition: the element at the given index has been changed to element.

Return: the old element at the given position.

 

public Object remove(int index)

Change the object at a given location.

Precondition: the index is valid.

Precondition: the element at the given index has been changed to element.

Return: the old element at the given position.

 

public int capacity()

Capacity accessor

Return: number of elements that the array can hold.

 

 


Back to the package documentation index


Back to the Introduction


Copyright 2000 by Prentice Hall. All rights reserved.