Constructs an empty list.
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
Appends the specified element to the end of this list.
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
Inserts the specified element at the beginning of this list.
Appends the specified element to the end of this list.
Removes all of the elements from this list. The list will be empty after this call returns.
Returns {@code true} if this list contains the specified element. More formally, returns {@code true} if and only if this list contains at least one element {@code e} such that <tt>(o==null ? e==null : o.equals(e))</tt>.
Retrieves, but does not remove, the head (first element) of this list.
Returns the element at the specified position in this list.
Returns the first element in this list.
Returns the last element in this list.
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index {@code i} such that <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, or -1 if there is no such index.
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index {@code i} such that <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, or -1 if there is no such index.
Links e as last element.
Adds the specified element as the tail (last element) of this list.
Inserts the specified element at the front of this list.
Inserts the specified element at the end of this list.
Retrieves, but does not remove, the head (first element) of this list.
Retrieves, but does not remove, the first element of this list, or returns {@code null} if this list is empty.
Retrieves, but does not remove, the last element of this list, or returns {@code null} if this list is empty.
Retrieves and removes the head (first element) of this list.
Retrieves and removes the first element of this list, or returns {@code null} if this list is empty.
Retrieves and removes the last element of this list, or returns {@code null} if this list is empty.
Pops an element from the stack represented by this list. In other words, removes and returns the first element of this list.
Pushes an element onto the stack represented by this list. In other words, inserts the element at the front of this list.
Removes the first occurrence of the specified element from this list, if it is present. If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index {@code i} such that <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt> (if such an element exists). Returns {@code true} if this list contained the specified element (or equivalently, if this list changed as a result of the call).
Retrieves and removes the head (first element) of this list.
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
Removes and returns the first element from this list.
Removes the first occurrence of the specified element in this list (when traversing the list from head to tail). If the list does not contain the element, it is unchanged.
Removes and returns the last element from this list.
Replaces the element at the specified position in this list with the specified element.
Returns the number of elements in this list.
Returns an array containing all of the elements in this list in proper sequence (from first to last element).
Doubly-linked list implementation of the {@code List} and {@code Deque} interfaces. Implements all optional list operations, and permits all elements (including {@code null}).
<p>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 beginning or the end, whichever is closer to the specified index.
<p><strong>Note that this implementation is not synchronized.</strong> If multiple threads access a linked list concurrently, and at least one of the threads modifies the list structurally, it <i>must</i> 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 list.
If no such object exists, the list should be "wrapped" using the {@link Collections#synchronizedList Collections.synchronizedList} method. This is best done at creation time, to prevent accidental unsynchronized access to the list:<pre> List list = Collections.synchronizedList(new LinkedList(...));</pre>
<p>The iterators returned by this class's {@code iterator} and {@code listIterator} methods are <i>fail-fast</i>: if the list is structurally modified at any time after the iterator is created, in any way except through the Iterator's own {@code remove} or {@code add} methods, the iterator will throw a {@link 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.
<p>Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw {@code ConcurrentModificationException} on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: <i>the fail-fast behavior of iterators should be used only to detect bugs.</i>
<p>This class is a member of the <a href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections Framework</a>.
@author Josh Bloch @see List @see ArrayList @param E the type of elements held in this collection