[all packages]
[package java.util]
[class hierarchy]
[index]
java.lang.Object | +----java.util.AbstractCollection<A> | +----java.util.AbstractList<A> | +----java.util.AbstractSequentialList<A> | +----java.util.LinkedList<A>
public class LinkedList<A> extends AbstractSequentialList<A> implements List<A>, Cloneable, java.io.Serializable
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.
public LinkedList();
public LinkedList(Collection<A> c);
getFirst
public A getFirst();
public A getLast();
public A removeFirst();
public A removeLast();
public void addFirst(A o);
public void addLast(A o);
public int size();
public void clear();
public ListIterator<A> 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.
public Object clone();
private class ListItr
private class ListItr implements ListIterator<A>
private static class Entry<A>
private static class Entry<A>
[all packages]
[package java.util]
[class hierarchy]
[index]
java.util.LinkedList.html