public class LinkedList4D<T>
extends java.util.AbstractSequentialList<T>
implements java.util.List<T>, java.util.Deque<T>, java.lang.Cloneable
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)
Constructor and Description |
---|
LinkedList4D()
Create an empty linked list.
|
LinkedList4D(java.util.Collection<? extends T> c)
Create a linked list containing the elements, in order, of a given
collection.
|
Modifier and Type | Method and Description |
---|---|
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(java.util.Collection<? extends T> c)
Append the elements of the collection in iteration order to the end of
this list.
|
boolean |
addAll(int index,
java.util.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.
|
java.lang.Object |
clone()
Create a shallow copy of this LinkedList (the elements are not cloned).
|
boolean |
contains(java.lang.Object o)
Returns true if the list contains the given object.
|
java.util.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(java.lang.Object o)
Returns the first index where the element is located in the list, or -1.
|
int |
lastIndexOf(java.lang.Object o)
Returns the last index where the element is located in the list, or -1.
|
java.util.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(java.lang.Object o)
Removes the entry at the lowest index in the list that matches the given
object, comparing by
o == null ? e = null : o.equals(e) . |
T |
removeFirst()
Remove and return the first element in the list.
|
boolean |
removeFirstOccurrence(java.lang.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(java.lang.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.
|
java.lang.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.
|
equals, hashCode, listIterator, removeRange, subList
containsAll, isEmpty, removeAll, retainAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
public LinkedList4D()
public LinkedList4D(java.util.Collection<? extends T> c)
c
- the collection to populate this list fromjava.lang.NullPointerException
- if c is nullpublic T getFirst()
getFirst
in interface java.util.Deque<T>
java.util.NoSuchElementException
- if the list is emptypublic T getLast()
getLast
in interface java.util.Deque<T>
java.util.NoSuchElementException
- if the list is emptypublic T removeFirst()
removeFirst
in interface java.util.Deque<T>
java.util.NoSuchElementException
- if the list is emptypublic T removeLast()
removeLast
in interface java.util.Deque<T>
java.util.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(java.lang.Object o)
o == null ? e = null : o.equals(e)
.public int size()
public boolean add(T o)
add
in interface java.util.Collection<T>
add
in interface java.util.Deque<T>
add
in interface java.util.List<T>
add
in interface java.util.Queue<T>
add
in class java.util.AbstractList<T>
o
- the entry to addpublic boolean remove(java.lang.Object o)
o == null ? e = null : o.equals(e)
.remove
in interface java.util.Collection<T>
remove
in interface java.util.Deque<T>
remove
in interface java.util.List<T>
remove
in class java.util.AbstractCollection<T>
o
- the object to removepublic boolean addAll(java.util.Collection<? extends T> c)
addAll
in interface java.util.Collection<T>
addAll
in interface java.util.List<T>
addAll
in class java.util.AbstractCollection<T>
c
- the collection to appendjava.lang.NullPointerException
- if c is nullpublic boolean addAll(int index, java.util.Collection<? extends T> c)
addAll
in interface java.util.List<T>
addAll
in class java.util.AbstractSequentialList<T>
c
- the collection to appendjava.lang.NullPointerException
- if c is nulljava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()public void clear()
public T get(int index)
public void add(int index, T o)
public T remove(int index)
public int indexOf(java.lang.Object o)
public int lastIndexOf(java.lang.Object o)
public java.util.ListIterator<T> listIterator(int index)
listIterator
in interface java.util.List<T>
listIterator
in class java.util.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 listjava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.Object[] toArray()
public <S> S[] toArray(S[] a)
toArray
in interface java.util.Collection<T>
toArray
in interface java.util.List<T>
toArray
in class java.util.AbstractCollection<T>
a
- the passed-in Arrayjava.lang.ArrayStoreException
- if the runtime type of a does not allow
an element in this listjava.lang.NullPointerException
- if a is nullpublic boolean offer(T value)
public T element()
public T peek()
public T poll()
public T remove()
public java.util.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>
java.util.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.java.util.NoSuchElementException
- if the list is empty.#addFirst(T)
public boolean removeFirstOccurrence(java.lang.Object o)
remove(Object)
.removeFirstOccurrence
in interface java.util.Deque<T>
o
- the element to remove.public boolean removeLastOccurrence(java.lang.Object o)
removeLastOccurrence
in interface java.util.Deque<T>
o
- the element to remove.