|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.AbstractSequentialList<T>
java.util.LinkedList<T>
public class LinkedList<T>
Linked list implementation of the List interface. In addition to the methods of the List interface, this class provides access to the first and last list elements in O(1) time for easy stack, queue, or double-ended queue (deque) creation. The list is doubly-linked, with traversal to a given index starting from the end closest to the element.
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
ConcurrentModificationException rather than exhibit
non-deterministic behavior.
List,
ArrayList,
Vector,
Collections.synchronizedList(List),
Serialized Form| Field Summary |
|---|
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| 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 | ||
|---|---|---|
void |
add(int index,
T o)
Inserts an element in the given position in the list. |
|
boolean |
add(T o)
Adds an element to the end of 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. |
|
T |
remove()
Removes and returns the first element of the list. |
|
T |
remove(int index)
Removes the element at the given position from 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 |
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. |
|
|
toArray(S[] a)
Returns an Array whose component type is the runtime component type of the passed-in Array. |
|
| Methods inherited from class java.util.AbstractSequentialList |
|---|
iterator |
| Methods inherited from class java.util.AbstractList |
|---|
equals, hashCode, listIterator, removeRange, subList |
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, isEmpty, removeAll, retainAll, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.List |
|---|
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList |
| Methods inherited from interface java.util.Deque |
|---|
iterator |
| Constructor Detail |
|---|
public LinkedList()
public LinkedList(Collection<? extends T> c)
c - the collection to populate this list from
NullPointerException - if c is null| Method Detail |
|---|
public T getFirst()
getFirst in interface java.util.Deque<T>NoSuchElementException - if the list is emptypublic T getLast()
getLast in interface java.util.Deque<T>NoSuchElementException - if the list is emptypublic T removeFirst()
removeFirst in interface java.util.Deque<T>NoSuchElementException - if the list is emptypublic T removeLast()
removeLast in interface java.util.Deque<T>NoSuchElementException - if the list is emptypublic void addFirst(T o)
addFirst in interface java.util.Deque<T>o - the element to insertpublic void addLast(T o)
addLast in interface java.util.Deque<T>o - the element to insertpublic boolean contains(Object o)
o == null ? e = null : o.equals(e).
contains in interface Collection<T>contains in interface java.util.Deque<T>contains in interface List<T>contains in class AbstractCollection<T>o - the element to look for
public int size()
size in interface Collection<T>size in interface java.util.Deque<T>size in interface List<T>size in class AbstractCollection<T>public boolean add(T o)
add in interface Collection<T>add in interface java.util.Deque<T>add in interface List<T>add in interface java.util.Queue<T>add in class AbstractList<T>o - the entry to add
AbstractList.add(int, Object)public boolean remove(Object o)
o == null ? e = null : o.equals(e).
remove in interface Collection<T>remove in interface java.util.Deque<T>remove in interface List<T>remove in class AbstractCollection<T>o - the object to remove
Iterator.remove()public boolean addAll(Collection<? extends T> c)
addAll in interface Collection<T>addAll in interface List<T>addAll in class AbstractCollection<T>c - the collection to append
NullPointerException - if c is nullAbstractCollection.add(Object)
public boolean addAll(int index,
Collection<? extends T> c)
addAll in interface List<T>addAll in class AbstractSequentialList<T>c - the collection to appendindex - the location to insert the collection
NullPointerException - if c is null
IndexOutOfBoundsException - if index < 0 || index > size()AbstractSequentialList.add(int, Object)public void clear()
clear in interface Collection<T>clear in interface List<T>clear in class AbstractList<T>AbstractList.remove(int),
AbstractList.removeRange(int, int)public T get(int index)
get in interface List<T>get in class AbstractSequentialList<T>index - the place to look
IndexOutOfBoundsException - if index < 0 || index >= size()
public T set(int index,
T o)
set in interface List<T>set in class AbstractSequentialList<T>index - which index to changeo - the new element
IndexOutOfBoundsException - if index < 0 || index >= size()
public void add(int index,
T o)
add in interface List<T>add in class AbstractSequentialList<T>index - where to insert the elemento - the element to insert
IndexOutOfBoundsException - if index < 0 || index > size()AbstractList.modCountpublic T remove(int index)
remove in interface List<T>remove in class AbstractSequentialList<T>index - the location of the element to remove
IndexOutOfBoundsException - if index < 0 || index > size()AbstractList.modCountpublic int indexOf(Object o)
indexOf in interface List<T>indexOf in class AbstractList<T>o - the element to look for
public int lastIndexOf(Object o)
lastIndexOf in interface List<T>lastIndexOf in class AbstractList<T>o - the element to look for
public ListIterator<T> listIterator(int index)
listIterator in interface List<T>listIterator in class AbstractSequentialList<T>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
IndexOutOfBoundsException - if index < 0 || index > size()AbstractList.modCountpublic Object clone()
clone in class ObjectCloneablepublic Object[] toArray()
toArray in interface Collection<T>toArray in interface List<T>toArray in class AbstractCollection<T>public <S> S[] toArray(S[] a)
toArray in interface Collection<T>toArray in interface List<T>toArray in class AbstractCollection<T>a - the passed-in Array
ArrayStoreException - if the runtime type of a does not allow
an element in this list
NullPointerException - if a is nullpublic boolean offer(T value)
offer in interface java.util.Deque<T>offer in interface java.util.Queue<T>value - the value to add.
public T element()
element in interface java.util.Deque<T>element in interface java.util.Queue<T>NoSuchElementException - if the list is empty.public T peek()
peek in interface java.util.Deque<T>peek in interface java.util.Queue<T>null
if the list is empty.public T poll()
poll in interface java.util.Deque<T>poll in interface java.util.Queue<T>null
if the list is empty.public T remove()
remove in interface java.util.Deque<T>remove in interface java.util.Queue<T>NoSuchElementException - if the list is empty.public Iterator<T> descendingIterator()
descendingIterator in interface java.util.Deque<T>public boolean offerFirst(T value)
offerFirst in interface java.util.Deque<T>value - the element to insert.
public boolean offerLast(T value)
offerLast in interface java.util.Deque<T>value - the element to insert.
public T peekFirst()
peekFirst in interface java.util.Deque<T>null
if the list is empty.public T peekLast()
peekLast in interface java.util.Deque<T>null
if the list is empty.public T pollFirst()
pollFirst in interface java.util.Deque<T>null
if the list is empty.public T pollLast()
pollLast in interface java.util.Deque<T>null
if the list is empty.public T pop()
removeFirst().
pop in interface java.util.Deque<T>NoSuchElementException - if the list is empty.removeFirst()public void push(T value)
#addFirst(T).
push in interface java.util.Deque<T>value - the element to push on to the stack.
NoSuchElementException - if the list is empty.#addFirst(T)public boolean removeFirstOccurrence(Object o)
remove(Object).
removeFirstOccurrence in interface java.util.Deque<T>o - the element to remove.
public boolean removeLastOccurrence(Object o)
removeLastOccurrence in interface java.util.Deque<T>o - the element to remove.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||