RetroArrayList

 

RetroLinkedList.java provides a 1.1 version of LinkedList which implements some of the Java 1.2 List interface

 

 

public RetroLinkedList()

Default constructor

Postcondition: Empty list is constructed.

 

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 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.

 

 


Back to the package documentation index


Back to the Introduction


Copyright 2000 by Prentice Hall. All rights reserved.