|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectDataStructures.LinkedList<E>
E - the type of elements held in this listpublic class LinkedList<E>
A simple implementation of singly linked lists.
Lists are created empty. Items can be inserted at the front of the list by
list.addFirst(item)where item is any item of type E.
Items can be removed from the front of the list by
list.removeFirst();which removes the first item from the list. Lists can be traversed using an iterator, for example:
for (Integer i : list) {
System.out.println(i);
}
| Constructor Summary | |
|---|---|
LinkedList()
Constructs an empty list suitable for holding items of type E. |
|
| Method Summary | |
|---|---|
void |
addFirst(E item)
Inserts an item at the front of the list. |
boolean |
contains(E item)
Tests whether an item is present in the list. |
boolean |
equals(java.lang.Object other)
Implements the equals method. |
E |
firstItem()
Returns the first item in the list without removing it. |
boolean |
isEmpty()
Tests if the list is empty. |
java.util.Iterator<E> |
iterator()
Iterates over the items in the list. |
void |
removeFirst()
Removes the first item from the list without returning it. |
void |
reverse()
Reverses the list. |
int |
size()
Returns the length of the list |
java.lang.String |
toString()
Converts the list to a string. |
| Methods inherited from class java.lang.Object |
|---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public LinkedList()
| Method Detail |
|---|
public boolean isEmpty()
public int size()
public void addFirst(E item)
item - the item of type E to be inserted.public E firstItem()
java.util.NoSuchElementException - if the list is empty.public void removeFirst()
java.util.NoSuchElementException - if the list is empty.public boolean contains(E item)
item - the item of type E to be searched for.
public void reverse()
public java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>java.util.NoSuchElementException - if the next method
is called when there is no next element
java.lang.IllegalStateException - if the next method has not
yet been called, or the remove method has already
been called after the last call to the next
method.public boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - the second linked list.
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||