public class LinkedList extends AbstractSequentialList implements List, Cloneable, Serializable
modCount
Constructor and Description |
---|
LinkedList() |
LinkedList(Collection c) |
Modifier and Type | Method and Description |
---|---|
void |
add(int idx,
Object e)
Inserts the specified object into this List at the specified location.
|
boolean |
add(Object e)
Adds the specified object at the end of this List.
|
boolean |
addAll(Collection c)
Attempts to add all of the objects contained in
collection
to the contents of this Collection (optional). |
boolean |
addAll(int idx,
Collection c)
Inserts the objects in the specified Collection at the specified location
in this List.
|
void |
addFirst(Object e) |
void |
addLast(Object e) |
void |
clear()
Removes all elements from this list, leaving it empty.
|
Object |
clone()
Default clone() method performs a "shallow" cloning of the instance.
|
boolean |
contains(Object o)
Tests whether this
Collection contains the specified object. |
Object |
getFirst() |
Object |
getLast() |
int |
indexOf(Object o)
Searches this list for the specified object and returns the index of the
first occurrence.
|
int |
lastIndexOf(Object o)
Searches this list for the specified object and returns the index of the
last occurrence.
|
ListIterator |
listIterator(int i)
Returns a list iterator on the elements of this list.
|
Object |
remove(int idx)
Removes the object at the specified location from this list.
|
boolean |
remove(Object e)
Removes one instance of the specified object from this
Collection if one
is contained (optional). |
Object |
removeFirst() |
Object |
removeLast() |
Object |
set(int idx,
Object e)
Replaces the element at the specified location in this list with the
specified object.
|
int |
size()
Returns a count of how many objects this
Collection contains. |
Object[] |
toArray() |
Object[] |
toArray(Object[] arr) |
get, iterator
equals, hashCode, listIterator, removeRange, subList
containsAll, isEmpty, removeAll, retainAll, toString
public LinkedList()
public LinkedList(Collection c)
public boolean add(Object e)
AbstractList
add
in interface Collection
add
in interface List
add
in class AbstractList
e
- the object to addpublic void addLast(Object e)
public void addFirst(Object e)
public void clear()
AbstractList
clear
in interface Collection
clear
in interface List
clear
in class AbstractList
List.isEmpty()
,
List.size()
public Object getFirst()
public Object getLast()
public Object removeFirst()
public Object removeLast()
public boolean addAll(Collection c)
AbstractCollection
collection
to the contents of this Collection
(optional). This implementation
iterates over the given Collection
and calls add
for each
element. If any of these calls return true
, then true
is
returned as result of this method call, false
otherwise. If this
Collection
does not support adding elements, an UnsupportedOperationException
is thrown.
If the passed Collection
is changed during the process of adding elements
to this Collection
, the behavior depends on the behavior of the passed
Collection
.
addAll
in interface Collection
addAll
in interface List
addAll
in class AbstractCollection
c
- the collection of objects.true
if this Collection
is modified, false
otherwise.public boolean addAll(int idx, Collection c)
AbstractList
addAll
in interface List
addAll
in class AbstractSequentialList
idx
- the index at which to insert.c
- the Collection of objectstrue
if this List is modified, false
otherwise.public void add(int idx, Object e)
AbstractList
Concrete implementations that would like to support the add functionality must override this method.
add
in interface List
add
in class AbstractSequentialList
idx
- the index at which to insert.e
- the object to add.public Object remove(int idx)
AbstractList
remove
in interface List
remove
in class AbstractSequentialList
idx
- the index of the object to remove.public Object set(int idx, Object e)
AbstractList
set
in interface List
set
in class AbstractSequentialList
idx
- the index at which to put the specified object.e
- the object to add.public boolean contains(Object o)
AbstractCollection
Collection
contains the specified object. This
implementation iterates over this Collection
and tests, whether any
element is equal to the given object. If object != null
then
object.equals(e)
is called for each element e
returned by
the iterator until the element is found. If object == null
then
each element e
returned by the iterator is compared with the test
e == null
.contains
in interface Collection
contains
in interface List
contains
in class AbstractCollection
o
- the object to search for.true
if object is an element of this Collection
, false
otherwise.public int indexOf(Object o)
AbstractList
indexOf
in interface List
indexOf
in class AbstractList
o
- the object to search for.public int lastIndexOf(Object o)
AbstractList
lastIndexOf
in interface List
lastIndexOf
in class AbstractList
o
- the object to search for.public boolean remove(Object e)
AbstractCollection
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.remove
in interface Collection
remove
in interface List
remove
in class AbstractCollection
e
- the object to remove.true
if this Collection
is modified, false
otherwise.public Object[] toArray()
toArray
in interface Collection
toArray
in interface List
toArray
in class AbstractCollection
public Object[] toArray(Object[] arr)
toArray
in interface Collection
toArray
in interface List
toArray
in class AbstractCollection
public Object clone()
Object
public int size()
AbstractCollection
Collection
contains.
In this class this method is declared abstract and has to be implemented
by concrete Collection
implementations.
size
in interface Collection
size
in interface List
size
in class AbstractCollection
Collection
contains, or Integer.MAX_VALUE
if there are more than Integer.MAX_VALUE
elements in this
Collection
.public ListIterator listIterator(int i)
AbstractList
listIterator
in interface List
listIterator
in class AbstractSequentialList
i
- the index at which to start the iteration.ListIterator