java.lang.Object | ||||
↳ | java.util.AbstractCollection<E> | |||
↳ | java.util.AbstractList<E> | |||
↳ | java.util.AbstractSequentialList<E> | |||
↳ | java.util.LinkedList<E> |
LinkedList is an implementation of List
, backed by a doubly-linked list. All optional operations including adding, removing, and replacing elements are supported.
All elements are permitted, including null.
This class is primarily useful if you need queue-like behavior. It may also be useful as a list if you expect your lists to contain zero or one element, but still require the ability to scale to slightly larger numbers of elements. In general, though, you should probably use ArrayList
if you don't need the queue-like behavior.
[Expand]
Inherited Fields
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Constructs a new empty instance of
LinkedList .
|
||||||||||
|
Constructs a new instance of
LinkedList that holds all of the elements contained in the specified
collection .
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Adds the specified object at the end of this
LinkedList .
|
||||||||||
|
Inserts the specified object into this
LinkedList at the specified location.
|
||||||||||
|
Adds the objects in the specified Collection to this
LinkedList .
|
||||||||||
|
Inserts the objects in the specified collection at the specified location in this
LinkedList .
|
||||||||||
|
Adds the specified object at the beginning of this
LinkedList .
|
||||||||||
|
Adds the specified object at the end of this
LinkedList .
|
||||||||||
|
Removes all elements from this
LinkedList , leaving it empty.
|
||||||||||
|
Returns a new
LinkedList with the same elements and size as this
LinkedList .
|
||||||||||
|
Searches this
LinkedList for the specified object.
|
||||||||||
|
Returns an iterator over the elements in this deque in reverse sequential order.
|
||||||||||
|
Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque).
|
||||||||||
|
Returns the element at the specified location in this list.
|
||||||||||
|
Returns the first element in this
LinkedList .
|
||||||||||
|
Returns the last element in this
LinkedList .
|
||||||||||
|
Searches this list for the specified object and returns the index of the first occurrence.
|
||||||||||
|
Searches this
LinkedList for the specified object and returns the index of the last occurrence.
|
||||||||||
|
Returns a ListIterator on the elements of this
LinkedList .
|
||||||||||
|
Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning
true upon success and
false if no space is currently available.
|
||||||||||
|
Inserts the specified element at the front of this deque unless it would violate capacity restrictions.
|
||||||||||
|
Inserts the specified element at the end of this deque unless it would violate capacity restrictions.
|
||||||||||
|
Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns
null if this deque is empty.
|
||||||||||
|
Retrieves, but does not remove, the first element of this deque, or returns
null if this deque is empty.
|
||||||||||
|
Retrieves, but does not remove, the last element of this deque, or returns
null if this deque is empty.
|
||||||||||
|
Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns
null if this deque is empty.
|
||||||||||
|
Retrieves and removes the first element of this deque, or returns
null if this deque is empty.
|
||||||||||
|
Retrieves and removes the last element of this deque, or returns
null if this deque is empty.
|
||||||||||
|
Pops an element from the stack represented by this deque.
|
||||||||||
|
Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, returning
true upon success and throwing an
IllegalStateException if no space is currently available.
|
||||||||||
|
Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque).
|
||||||||||
|
Removes the object at the specified location from this
LinkedList .
|
||||||||||
|
Removes one instance of the specified object from this
Collection if one is contained (optional).
|
||||||||||
|
Removes the first object from this
LinkedList .
|
||||||||||
|
Removes the first occurrence of the specified element from this deque.
|
||||||||||
|
Removes the last object from this
LinkedList .
|
||||||||||
|
Removes the last occurrence of the specified element from this deque.
|
||||||||||
|
Replaces the element at the specified location in this
LinkedList with the specified object.
|
||||||||||
|
Returns the number of elements in this
LinkedList .
|
||||||||||
|
Returns an array containing all elements contained in this
LinkedList .
|
||||||||||
|
Returns a new array containing all elements contained in this
LinkedList .
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
|||||||||||
![]() |
|||||||||||
![]() |
|||||||||||
![]() |
|||||||||||
![]() |
|||||||||||
![]() |
|||||||||||
![]() |
|||||||||||
![]() |
|||||||||||
![]() |
Constructs a new instance of LinkedList
that holds all of the elements contained in the specified collection
. The order of the elements in this new LinkedList
will be determined by the iteration order of collection
.
collection | the collection of elements to add. |
---|
Adds the specified object at the end of this LinkedList
.
object | the object to add. |
---|
Inserts the specified object into this LinkedList
at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this LinkedList
, the object is added at the end.
location | the index at which to insert. |
---|---|
object | the object to add. |
IndexOutOfBoundsException | if location < 0 || location > size() |
---|
Adds the objects in the specified Collection to this LinkedList
.
collection | the collection of objects. |
---|
true
if this LinkedList
is modified, false
otherwise. Inserts the objects in the specified collection at the specified location in this LinkedList
. The objects are added in the order they are returned from the collection's iterator.
location | the index at which to insert. |
---|---|
collection | the collection of objects |
true
if this LinkedList
is modified, false
otherwise.ClassCastException | if the class of an object is inappropriate for this list. |
---|---|
IllegalArgumentException | if an object cannot be added to this list. |
IndexOutOfBoundsException | if location < 0 || location > size() |
Adds the specified object at the beginning of this LinkedList
.
object | the object to add. |
---|
Adds the specified object at the end of this LinkedList
.
object | the object to add. |
---|
Returns a new LinkedList
with the same elements and size as this LinkedList
.
LinkedList
.Searches this LinkedList
for the specified object.
object | the object to search for. |
---|
true
if object
is an element of this LinkedList
, false
otherwise Returns an iterator over the elements in this deque in reverse sequential order. The elements will be returned in order from last (tail) to first (head).
Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque). This method differs from peek
only in that it throws an exception if this deque is empty.
This method is equivalent to getFirst()
.
Returns the element at the specified location in this list.
location | the index of the element to return. |
---|
Returns the first element in this LinkedList
.
NoSuchElementException | if this LinkedList is empty. |
---|
Returns the last element in this LinkedList
.
NoSuchElementException | if this LinkedList is empty |
---|
Searches this list for the specified object and returns the index of the first occurrence.
object | the object to search for. |
---|
Searches this LinkedList
for the specified object and returns the index of the last occurrence.
object | the object to search for |
---|
Returns a ListIterator on the elements of this LinkedList
. The elements are iterated in the same order that they occur in the LinkedList
. The iteration starts at the specified location.
location | the index at which to start the iteration |
---|
LinkedList
IndexOutOfBoundsException | if location < 0 || location > size() |
---|
Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available. When using a capacity-restricted deque, this method is generally preferable to the add(E)
method, which can fail to insert an element only by throwing an exception.
This method is equivalent to offerLast(E)
.
o | the element to add |
---|
Inserts the specified element at the front of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the addFirst(E)
method, which can fail to insert an element only by throwing an exception.
e | the element to add |
---|
Inserts the specified element at the end of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the addLast(E)
method, which can fail to insert an element only by throwing an exception.
e | the element to add |
---|
Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.
This method is equivalent to peekFirst()
.
Retrieves, but does not remove, the first element of this deque, or returns null if this deque is empty.
Retrieves, but does not remove, the last element of this deque, or returns null if this deque is empty.
Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.
This method is equivalent to pollFirst()
.
Retrieves and removes the first element of this deque, or returns null if this deque is empty.
Retrieves and removes the last element of this deque, or returns null if this deque is empty.
Pops an element from the stack represented by this deque. In other words, removes and returns the first element of this deque.
This method is equivalent to removeFirst()
.
Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.
This method is equivalent to addFirst(E)
.
e | the element to push |
---|
Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque). This method differs from poll
only in that it throws an exception if this deque is empty.
This method is equivalent to removeFirst()
.
Removes the object at the specified location from this LinkedList
.
location | the index of the object to remove |
---|
IndexOutOfBoundsException | if location < 0 || location >= size() |
---|
Removes one instance of the specified object from this Collection
if one is contained (optional). This implementation iterates over this Collection
and tests for each element e
returned by the iterator, whether e
is equal to the given object. If object != null
then this test is performed using object.equals(e)
, otherwise using object == null
. If an element equal to the given object is found, then the remove
method is called on the iterator and true
is returned, false
otherwise. If the iterator does not support removing elements, an UnsupportedOperationException
is thrown.
object | the object to remove. |
---|
true
if this Collection
is modified, false
otherwise.Removes the first object from this LinkedList
.
NoSuchElementException | if this LinkedList is empty. |
---|
Removes the first occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More formally, removes the first element e such that (o==null ? e==null : o.equals(e)) (if such an element exists). Returns true if this deque contained the specified element (or equivalently, if this deque changed as a result of the call).
o | element to be removed from this deque, if present |
---|
Removes the last object from this LinkedList
.
NoSuchElementException | if this LinkedList is empty. |
---|
Removes the last occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More formally, removes the last element e such that (o==null ? e==null : o.equals(e)) (if such an element exists). Returns true if this deque contained the specified element (or equivalently, if this deque changed as a result of the call).
o | element to be removed from this deque, if present |
---|
Replaces the element at the specified location in this LinkedList
with the specified object.
location | the index at which to put the specified object. |
---|---|
object | the object to add. |
ClassCastException | if the class of an object is inappropriate for this list. |
---|---|
IllegalArgumentException | if an object cannot be added to this list. |
IndexOutOfBoundsException | if location < 0 || location >= size() |
Returns the number of elements in this LinkedList
.
LinkedList
. Returns an array containing all elements contained in this LinkedList
. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than this LinkedList
, the array element following the collection elements is set to null.
contents | the array. |
---|
LinkedList
.ArrayStoreException | if the type of an element in this LinkedList cannot be stored in the type of the specified array. |
---|
Returns a new array containing all elements contained in this LinkedList
.
LinkedList
.