|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface describing lists. Lists are collections of data with a head and tail. Values may be added or removed from either end, as well as by value from the middle. The structure package provides several implementations of the List interface, each of which has its particular strengths and weaknesses.
Example usage:
To place a copy of every unique parameter passed to a program into a List, we could use the following:
public static void main(String[]
arguments) {List
argList = newSinglyLinkedList()
; for (int i = 0; i < arguments.length; i++){ if (!argList.contains(arguments[i])
){ argList.add(arguments[i])
; } } System.out.println(argList); }
SinglyLinkedList
,
DoublyLinkedList
,
CircularList
Method Summary | |
void |
add(int i,
Object o)
Insert value at location. |
void |
add(Object value)
Add an object to tail of list. |
void |
addFirst(Object value)
Add a value to the head of the list. |
void |
addLast(Object value)
Add a value to tail of list. |
void |
clear()
Remove all elements of list. |
boolean |
contains(Object value)
Check to see if a value is in list. |
Object |
get()
Retrieves value from tail of list. |
Object |
get(int i)
Get value at location i. |
Object |
getFirst()
Fetch first element of list. |
Object |
getLast()
Fetch last element of list. |
int |
indexOf(Object value)
Determine first location of a value in list. |
boolean |
isEmpty()
Determine if list is empty. |
Iterator |
iterator()
Construct an iterator to traverse elements of list from head to tail, in order. |
int |
lastIndexOf(Object value)
Determine last location of a value in list. |
Object |
remove()
Removes value from tail of list. |
Object |
remove(int i)
Remove and return value at location i. |
Object |
remove(Object value)
Remove a value from list. |
Object |
removeFirst()
Remove a value from first element of list. |
Object |
removeLast()
Remove last value from list. |
Object |
set(int i,
Object o)
Set value stored at location i to object o, returning old value. |
int |
size()
Determine size of list. |
Methods inherited from interface structure.Structure |
elements, values |
Method Detail |
public int size()
size
in interface Structure
public boolean isEmpty()
isEmpty
in interface Structure
public void clear()
clear
in interface Structure
public void addFirst(Object value)
value
- The value to be added to the head of the list.public void addLast(Object value)
value
- The value to be added to tail of list.public Object getFirst()
public Object getLast()
public Object removeFirst()
public Object removeLast()
public Object remove(Object value)
remove
in interface Structure
value
- The value to be removed.public void add(Object value)
add
in interface Structure
value
- The value to be added to tail of list.addLast(java.lang.Object)
public Object remove()
public Object get()
public boolean contains(Object value)
contains
in interface Structure
value
- value sought.public int indexOf(Object value)
value
- The value sought.public int lastIndexOf(Object value)
value
- value sought.public Object get(int i)
i
- position of value to be retrieved.public Object set(int i, Object o)
i
- location of entry to be changed.o
- new valuepublic void add(int i, Object o)
i
- index of this new valueo
- value to be storedpublic Object remove(int i)
i
- position of value to be retrieved.public Iterator iterator()
iterator
in interface Structure
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |