java.util
public class LinkedList<T> extends AbstractSequentialList<T> implements List<T>, Deque<T>, Cloneable, Serializable
LinkedList is not synchronized, so if you need multi-threaded access,
consider using:
List l = Collections.synchronizedList(new LinkedList(...));
The iterators are fail-fast, meaning that any structural
modification, except for remove()
called on the iterator
itself, cause the iterator to throw a
{@link ConcurrentModificationException} rather than exhibit
non-deterministic behavior.
Since: 1.2
See Also: List ArrayList Vector synchronizedList
UNKNOWN: Complete to 1.6
Constructor Summary | |
---|---|
LinkedList()
Create an empty linked list. | |
LinkedList(Collection<? extends T> c)
Create a linked list containing the elements, in order, of a given
collection.
|
Method Summary | |
---|---|
boolean | add(T o)
Adds an element to the end of the list.
|
void | add(int index, T o)
Inserts an element in the given position in the list.
|
boolean | addAll(Collection<? extends T> c)
Append the elements of the collection in iteration order to the end of
this list. |
boolean | addAll(int index, Collection<? extends T> c)
Insert the elements of the collection in iteration order at the given
index of this list. |
void | addFirst(T o)
Insert an element at the first of the list.
|
void | addLast(T o)
Insert an element at the last of the list.
|
void | clear()
Remove all elements from this list. |
Object | clone()
Create a shallow copy of this LinkedList (the elements are not cloned).
|
boolean | contains(Object o)
Returns true if the list contains the given object. |
Iterator<T> | descendingIterator()
Obtain an Iterator over this list in reverse sequential order.
|
T | element()
Returns the first element of the list without removing
it.
|
T | get(int index)
Return the element at index.
|
T | getFirst()
Returns the first element in the list.
|
T | getLast()
Returns the last element in the list.
|
int | indexOf(Object o)
Returns the first index where the element is located in the list, or -1.
|
int | lastIndexOf(Object o)
Returns the last index where the element is located in the list, or -1.
|
ListIterator<T> | listIterator(int index)
Obtain a ListIterator over this list, starting at a given index. |
boolean | offer(T value)
Adds the specified element to the end of the list.
|
boolean | offerFirst(T value)
Inserts the specified element at the front of the list.
|
boolean | offerLast(T value)
Inserts the specified element at the end of the list.
|
T | peek()
Returns the first element of the list without removing
it.
|
T | peekFirst()
Returns the first element of the list without removing
it.
|
T | peekLast()
Returns the last element of the list without removing
it.
|
T | poll()
Removes and returns the first element of the list.
|
T | pollFirst()
Removes and returns the first element of the list.
|
T | pollLast()
Removes and returns the last element of the list.
|
T | pop()
Pops an element from the stack by removing and returning
the first element in the list. |
void | push(T value)
Pushes an element on to the stack by adding it to the
front of the list. |
boolean | remove(Object o)
Removes the entry at the lowest index in the list that matches the given
object, comparing by o == null ? |
T | remove(int index)
Removes the element at the given position from the list.
|
T | remove()
Removes and returns the first element of the list.
|
T | removeFirst()
Remove and return the first element in the list.
|
boolean | removeFirstOccurrence(Object o)
Removes the first occurrence of the specified element
from the list, when traversing the list from head to
tail. |
T | removeLast()
Remove and return the last element in the list.
|
boolean | removeLastOccurrence(Object o)
Removes the last occurrence of the specified element
from the list, when traversing the list from head to
tail. |
T | set(int index, T o)
Replace the element at the given location in the list.
|
int | size()
Returns the size of the list.
|
Object[] | toArray()
Returns an array which contains the elements of the list in order.
|
<S> S[] | toArray(S[] a)
Returns an Array whose component type is the runtime component type of
the passed-in Array. |
Parameters: c the collection to populate this list from
Throws: NullPointerException if c is null
Parameters: o the entry to add
Returns: true, as it always succeeds
Parameters: index where to insert the element o the element to insert
Throws: IndexOutOfBoundsException if index < 0 || index > size()
Parameters: c the collection to append
Returns: true if the list was modified
Throws: NullPointerException if c is null
Parameters: c the collection to append
Returns: true if the list was modified
Throws: NullPointerException if c is null IndexOutOfBoundsException if index < 0 || index > size()
Parameters: o the element to insert
Parameters: o the element to insert
Returns: an object of the same class as this object, containing the same elements in the same order
o == null ? e = null : o.equals(e)
.
Parameters: o the element to look for
Returns: true if it is found
Returns: an Iterator over the elements of the list in reverse order.
Since: 1.6
Returns: the first element of the list.
Throws: NoSuchElementException if the list is empty.
Since: 1.5
Parameters: index the place to look
Returns: the element at index
Throws: IndexOutOfBoundsException if index < 0 || index >= size()
Returns: the first list element
Throws: NoSuchElementException if the list is empty
Returns: the last list element
Throws: NoSuchElementException if the list is empty
Parameters: o the element to look for
Returns: its position, or -1 if not found
Parameters: o the element to look for
Returns: its position, or -1 if not found
Parameters: index the index of the element to be returned by the first call to next(), or size() to be initially positioned at the end of the list
Throws: IndexOutOfBoundsException if index < 0 || index > size()
Parameters: value the value to add.
Returns: true.
Since: 1.5
Parameters: value the element to insert.
Returns: true.
Since: 1.6
Parameters: value the element to insert.
Returns: true.
Since: 1.6
Returns: the first element of the list, or null
if the list is empty.
Since: 1.5
Returns: the first element of the list, or null
if the list is empty.
Since: 1.6
Returns: the last element of the list, or null
if the list is empty.
Since: 1.6
Returns: the first element of the list, or null
if the list is empty.
Since: 1.5
Returns: the first element of the list, or null
if the list is empty.
Since: 1.6
Returns: the last element of the list, or null
if the list is empty.
Since: 1.6
Returns: the top of the stack, which is the first element of the list.
Throws: NoSuchElementException if the list is empty.
Since: 1.6
See Also: removeFirst
Parameters: value the element to push on to the stack.
Throws: NoSuchElementException if the list is empty.
Since: 1.6
See Also: LinkedList
o == null ? e = null : o.equals(e)
.
Parameters: o the object to remove
Returns: true if an instance of the object was removed
Parameters: index the location of the element to remove
Returns: the removed element
Throws: IndexOutOfBoundsException if index < 0 || index > size()
Returns: the first element of the list.
Throws: NoSuchElementException if the list is empty.
Since: 1.5
Returns: the former first element in the list
Throws: NoSuchElementException if the list is empty
Parameters: o the element to remove.
Returns: true if an instance of the object was removed.
Since: 1.6
Returns: the former last element in the list
Throws: NoSuchElementException if the list is empty
Parameters: o the element to remove.
Returns: true if an instance of the object was removed.
Since: 1.6
Parameters: index which index to change o the new element
Returns: the prior element
Throws: IndexOutOfBoundsException if index < 0 || index >= size()
Returns: the list size
Returns: an array containing the list elements
Parameters: a the passed-in Array
Returns: an array representation of this list
Throws: ArrayStoreException if the runtime type of a does not allow an element in this list NullPointerException if a is null