public class LinkedList extends java.util.AbstractSequentialList implements java.util.List, Deque, java.lang.Cloneable, java.io.Serializable
Constructor and Description |
---|
LinkedList() |
LinkedList(java.util.Collection c) |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
java.lang.Object element) |
boolean |
add(java.lang.Object o)
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 throwing an
IllegalStateException if no space is currently available.
|
boolean |
addAll(java.util.Collection c) |
boolean |
addAll(int index,
java.util.Collection c) |
void |
addFirst(java.lang.Object e)
Inserts the specified element at the front of this deque if it is
possible to do so immediately without violating capacity restrictions.
|
void |
addLast(java.lang.Object e)
Inserts the specified element at the end of this deque if it is
possible to do so immediately without violating capacity restrictions.
|
void |
clear() |
java.lang.Object |
clone() |
boolean |
contains(java.lang.Object o)
Returns true if this deque contains the specified element.
|
java.util.Iterator |
descendingIterator()
Returns an iterator over the elements in this deque in reverse
sequential order.
|
java.lang.Object |
element()
Retrieves, but does not remove, the head of the queue represented by
this deque (in other words, the first element of this deque).
|
java.lang.Object |
get(int index) |
java.lang.Object |
getFirst()
Retrieves, but does not remove, the first element of this deque.
|
java.lang.Object |
getLast()
Retrieves, but does not remove, the last element of this deque.
|
int |
indexOf(java.lang.Object o) |
boolean |
isEmpty() |
int |
lastIndexOf(java.lang.Object o) |
java.util.ListIterator |
listIterator() |
java.util.ListIterator |
listIterator(int index) |
boolean |
offer(java.lang.Object e)
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.
|
boolean |
offerFirst(java.lang.Object e)
Inserts the specified element at the front of this deque unless it would
violate capacity restrictions.
|
boolean |
offerLast(java.lang.Object e)
Inserts the specified element at the end of this deque unless it would
violate capacity restrictions.
|
java.lang.Object |
peek()
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.
|
java.lang.Object |
peekFirst()
Retrieves, but does not remove, the first element of this deque,
or returns null if this deque is empty.
|
java.lang.Object |
peekLast()
Retrieves, but does not remove, the last element of this deque,
or returns null if this deque is empty.
|
java.lang.Object |
poll()
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.
|
java.lang.Object |
pollFirst()
Retrieves and removes the first element of this deque,
or returns null if this deque is empty.
|
java.lang.Object |
pollLast()
Retrieves and removes the last element of this deque,
or returns null if this deque is empty.
|
java.lang.Object |
pop()
Pops an element from the stack represented by this deque.
|
void |
push(java.lang.Object e)
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.
|
java.lang.Object |
remove()
Retrieves and removes the head of the queue represented by this deque
(in other words, the first element of this deque).
|
java.lang.Object |
remove(int index) |
boolean |
remove(java.lang.Object o)
Removes the first occurrence of the specified element from this deque.
|
java.lang.Object |
removeFirst()
Retrieves and removes the first element of this deque.
|
boolean |
removeFirstOccurrence(java.lang.Object o)
Removes the first occurrence of the specified element from this deque.
|
java.lang.Object |
removeLast()
Retrieves and removes the last element of this deque.
|
boolean |
removeLastOccurrence(java.lang.Object o)
Removes the last occurrence of the specified element from this deque.
|
java.lang.Object |
set(int index,
java.lang.Object element) |
int |
size()
Returns the number of elements in this deque.
|
java.lang.Object[] |
toArray() |
java.lang.Object[] |
toArray(java.lang.Object[] a) |
containsAll, removeAll, retainAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
public LinkedList()
public LinkedList(java.util.Collection c)
public int size()
Deque
public boolean isEmpty()
isEmpty
in interface java.util.Collection
isEmpty
in interface java.util.List
isEmpty
in class java.util.AbstractCollection
public boolean contains(java.lang.Object o)
Deque
contains
in interface Deque
contains
in interface java.util.Collection
contains
in interface java.util.List
contains
in class java.util.AbstractCollection
o
- element whose presence in this deque is to be testedpublic int indexOf(java.lang.Object o)
indexOf
in interface java.util.List
indexOf
in class java.util.AbstractList
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List
lastIndexOf
in class java.util.AbstractList
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
toArray
in interface java.util.List
toArray
in class java.util.AbstractCollection
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface java.util.Collection
toArray
in interface java.util.List
toArray
in class java.util.AbstractCollection
public boolean add(java.lang.Object o)
Deque
offer
.
This method is equivalent to Deque.addLast(java.lang.Object)
.
add
in interface Deque
add
in interface Queue
add
in interface java.util.Collection
add
in interface java.util.List
add
in class java.util.AbstractList
o
- the element to addCollection.add(java.lang.Object)
)public boolean remove(java.lang.Object o)
Deque
This method is equivalent to Deque.removeFirstOccurrence(java.lang.Object)
.
remove
in interface Deque
remove
in interface java.util.Collection
remove
in interface java.util.List
remove
in class java.util.AbstractCollection
o
- element to be removed from this deque, if presentpublic boolean addAll(java.util.Collection c)
addAll
in interface java.util.Collection
addAll
in interface java.util.List
addAll
in class java.util.AbstractCollection
public boolean addAll(int index, java.util.Collection c)
addAll
in interface java.util.List
addAll
in class java.util.AbstractSequentialList
public void clear()
clear
in interface java.util.Collection
clear
in interface java.util.List
clear
in class java.util.AbstractList
public java.lang.Object get(int index)
get
in interface java.util.List
get
in class java.util.AbstractSequentialList
public java.lang.Object set(int index, java.lang.Object element)
set
in interface java.util.List
set
in class java.util.AbstractSequentialList
public void add(int index, java.lang.Object element)
add
in interface java.util.List
add
in class java.util.AbstractSequentialList
public java.lang.Object remove(int index)
remove
in interface java.util.List
remove
in class java.util.AbstractSequentialList
public java.util.ListIterator listIterator()
listIterator
in interface java.util.List
listIterator
in class java.util.AbstractList
public java.util.ListIterator listIterator(int index)
listIterator
in interface java.util.List
listIterator
in class java.util.AbstractSequentialList
public void addFirst(java.lang.Object e)
Deque
Deque.offerFirst(java.lang.Object)
.public void addLast(java.lang.Object e)
Deque
Deque.offerLast(java.lang.Object)
.
This method is equivalent to Deque.add(java.lang.Object)
.
public boolean offerFirst(java.lang.Object e)
Deque
Deque.addFirst(java.lang.Object)
method,
which can fail to insert an element only by throwing an exception.offerFirst
in interface Deque
e
- the element to addpublic boolean offerLast(java.lang.Object e)
Deque
Deque.addLast(java.lang.Object)
method,
which can fail to insert an element only by throwing an exception.public java.lang.Object removeFirst()
Deque
pollFirst
only in that it throws an
exception if this deque is empty.removeFirst
in interface Deque
public java.lang.Object removeLast()
Deque
pollLast
only in that it throws an
exception if this deque is empty.removeLast
in interface Deque
public java.lang.Object pollFirst()
Deque
public java.lang.Object pollLast()
Deque
public java.lang.Object getFirst()
Deque
peekFirst
only in that it
throws an exception if this deque is empty.public java.lang.Object getLast()
Deque
peekLast
only in that it
throws an exception if this deque is empty.public java.lang.Object peekFirst()
Deque
public java.lang.Object peekLast()
Deque
public boolean removeFirstOccurrence(java.lang.Object o)
Deque
removeFirstOccurrence
in interface Deque
o
- element to be removed from this deque, if presentpublic boolean removeLastOccurrence(java.lang.Object o)
Deque
removeLastOccurrence
in interface Deque
o
- element to be removed from this deque, if presentpublic boolean offer(java.lang.Object e)
Deque
Deque.add(java.lang.Object)
method, which can fail to
insert an element only by throwing an exception.
This method is equivalent to Deque.offerLast(java.lang.Object)
.
public java.lang.Object remove()
Deque
poll
only in that it throws an
exception if this deque is empty.
This method is equivalent to Deque.removeFirst()
.
public java.lang.Object poll()
Deque
This method is equivalent to Deque.pollFirst()
.
public java.lang.Object element()
Deque
peek
only in that it throws an
exception if this deque is empty.
This method is equivalent to Deque.getFirst()
.
public java.lang.Object peek()
Deque
This method is equivalent to Deque.peekFirst()
.
public void push(java.lang.Object e)
Deque
This method is equivalent to Deque.addFirst(java.lang.Object)
.
public java.lang.Object pop()
Deque
This method is equivalent to Deque.removeFirst()
.
public java.util.Iterator descendingIterator()
Deque
descendingIterator
in interface Deque
public java.lang.Object clone()
clone
in class java.lang.Object