Class | Tree | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractCollection | +--java.util.AbstractList | +--java.util.AbstractSequentialList | +--java.util.LinkedList
All of the stack/queue/deque operations could be easily recast in terms of the standard List operations. They're included here primarily for convenience, though they may run slightly faster than the equivalent List operations.
All of the operations perform as could be expected for a doubly-linked list. Operations that index into the list will traverse the list from the begining or the end, whichever is closer to the specified index.
Note that this implementation is not synchronized. If multiple threads access a LinkedList concurrently, and at least one of the threads modifies the LinkedList structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the LinkedList. If no such object exists, the LinkedList should be "wrapped" using the Collections.synchronizedSet method. This is best done at creation time, to prevent accidental unsynchronized access to the LinkedList:
List list = Collections.synchronizedList(new LinkedList(...));
The Iterators returned by LinkedList's iterator and listIterator methods are fail-fast: if the LinkedList is structurally modified at any time after the Iterator is created, in any way except through the Iterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the Iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.
Fields inherited from class java.util.AbstractList | |
modCount |
Constructor Summary | |
LinkedList()
Constructs an empty Linked List. |
|
LinkedList(java.util.Collection c)
Constructs a LinkedList containing the elements of the specified Collection, in the order they are returned by the Collection's iterator. |
Method Summary | |
void | addFirst(java.lang.Object o)
Inserts the given element at the beginning of this List. |
void | addLast(java.lang.Object o)
Appends the given element to the end of this List. |
void | clear()
Removes all of the elements from this List. |
java.lang.Object | clone()
Returns a shallow copy of this LinkedList. |
java.lang.Object | getFirst()
Returns the first Element in this List. |
java.lang.Object | getLast()
Returns the last Element in this List. |
ListIterator | listIterator(int index)
Returns a ListIterator of the elements in this List (in proper sequence), starting at the specified position in the list. |
java.lang.Object | removeFirst()
Removes and returns the first Element from this List. |
java.lang.Object | removeLast()
Removes and returns the last Element from this List. |
int | size()
Returns the number of elements in this List. |
Methods inherited from class java.util.AbstractSequentialList | |
add, addAll, get, iterator, listIterator, remove, set |
Methods inherited from class java.util.AbstractList | |
add, add, addAll, equals, get, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, set, subList |
Methods inherited from class java.util.AbstractCollection | |
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object | |
Constructor Detail |
public LinkedList()
public LinkedList(java.util.Collection c)
Method Detail |
public java.lang.Object getFirst()
public java.lang.Object getLast()
public java.lang.Object removeFirst()
public java.lang.Object removeLast()
public void addFirst(java.lang.Object o)
public void addLast(java.lang.Object o)
public int size()
public void clear()
public ListIterator listIterator(int index)
The ListIterator is fail-fast: if the LinkedList is structurally modified at any time after the Iterator is created, in any way except through the ListIterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the Iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.
index
- index of first element to be returned from the
ListIterator (by a call to getNext).public java.lang.Object clone()
Class | Tree | Index | Help | |||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |