Android
java.util
public class

java.util.LinkedList<E>

java.lang.Object
java.util.AbstractCollection<E> Collection<E>
java.util.AbstractList<E> List<E>
java.util.AbstractSequentialList<E>
java.util.LinkedList<E> Serializable Cloneable List<E> Queue<E>

LinkedList is an implementation of List, backed by a linked list. All optional operations are supported, adding, removing and replacing. The elements can be any objects.

Summary

Fields inherited from class java.util.AbstractList

Public Constructors

            LinkedList()
Constructs a new empty instance of LinkedList.
            LinkedList(Collection<? extends E> collection)
Constructs a new instance of LinkedList that holds all of the elements contained in the supplied collection argument.

Public Methods

          void  add(int location, E object)
Inserts the specified object into this LinkedList at the specified location.
          boolean  add(E object)
Adds the specified object at the end of this LinkedList.
          boolean  addAll(int location, Collection<? extends E> collection)
Inserts the objects in the specified Collection at the specified location in this LinkedList.
          boolean  addAll(Collection<? extends E> collection)
Adds the objects in the specified Collection to this LinkedList.
          void  addFirst(E object)
Adds the specified object at the beginning of this LinkedList.
          void  addLast(E object)
Adds the specified object at the end of this LinkedList.
          void  clear()
Removes all elements from this LinkedList, leaving it empty.
          Object  clone()
Returns a new LinkedList with the same elements and size as this LinkedList.
          boolean  contains(Object object)
Searches this LinkedList for the specified object.
          element()
Gets but not removes the element in the head of the queue.
          get(int location)
Returns the element at the specified location in this List.
          getFirst()
Returns the first element in this LinkedList.
          getLast()
Returns the last element in this LinkedList.
          int  indexOf(Object object)
Searches this LinkedList for the specified object and returns the index of the first occurrence.
          int  lastIndexOf(Object object)
Searches this LinkedList for the specified object and returns the index of the last occurrence.
          ListIterator<E>  listIterator(int location)
Returns a ListIterator on the elements of this LinkedList.
          boolean  offer(E o)
Inserts the specified element into the queue provided that the condition allows such an operation.
          peek()
Gets but not removes the element in the head of the queue, or throws exception if there is no element in the queue.
          poll()
Gets and removes the element in the head of the queue, or returns null if there is no element in the queue.
          remove(int location)
Removes the object at the specified location from this LinkedList.
          remove()
Gets and removes the element in the head of the queue.
          boolean  remove(Object object)
Removes the first occurrence of the specified object from this Collection.
          removeFirst()
Removes the first object from this LinkedList.
          removeLast()
Removes the last object from this LinkedList.
          set(int location, E object)
Replaces the element at the specified location in this LinkedList with the specified object.
          int  size()
Returns the number of elements in this LinkedList.
        <T>  T[]  toArray(T[] contents)
Returns an array containing all elements contained in this LinkedList.
          Object[]  toArray()
Returns a new array containing all elements contained in this LinkedList.
Methods inherited from class java.util.AbstractSequentialList
Methods inherited from class java.util.AbstractList
Methods inherited from class java.util.AbstractCollection
Methods inherited from class java.lang.Object
Methods inherited from interface java.lang.Iterable
Methods inherited from interface java.util.Collection
Methods inherited from interface java.util.List
Methods inherited from interface java.util.Queue

Details

Public Constructors

public LinkedList()

Constructs a new empty instance of LinkedList.

public LinkedList(Collection<? extends E> collection)

Constructs a new instance of LinkedList that holds all of the elements contained in the supplied collection argument. The order of the elements in this new LinkedList will be determined by the iteration order of collection.

Parameters

collection the collection of elements to add

Public Methods

public void add(int location, E object)

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.

Parameters

location the index at which to insert
object the object to add

Throws

IndexOutOfBoundsException when location < 0 || >= size()

public boolean add(E object)

Adds the specified object at the end of this LinkedList.

Parameters

object the object to add

Returns

  • true

public boolean addAll(int location, Collection<? extends E> collection)

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 iterator.

Parameters

location the index at which to insert
collection the Collection of objects

Returns

  • true if this LinkedList is modified, false otherwise

Throws

IndexOutOfBoundsException when location < 0 || > size()

public boolean addAll(Collection<? extends E> collection)

Adds the objects in the specified Collection to this LinkedList.

Parameters

collection the Collection of objects

Returns

  • true if this LinkedList is modified, false otherwise

public void addFirst(E object)

Adds the specified object at the beginning of this LinkedList.

Parameters

object the object to add

public void addLast(E object)

Adds the specified object at the end of this LinkedList.

Parameters

object the object to add

public void clear()

Removes all elements from this LinkedList, leaving it empty.

See Also

public Object clone()

Returns a new LinkedList with the same elements and size as this LinkedList.

Returns

  • a shallow copy of this LinkedList

See Also

public boolean contains(Object object)

Searches this LinkedList for the specified object.

Parameters

object the object to search for

Returns

  • true if object is an element of this LinkedList, false otherwise

public E element()

Gets but not removes the element in the head of the queue. Throws a NoSuchElementException if there is no element in the queue.

public E get(int location)

Returns the element at the specified location in this List.

Parameters

location the index of the element to return

Returns

  • the element at the specified location

public E getFirst()

Returns the first element in this LinkedList.

Returns

  • the first element

Throws

NoSuchElementException when this LinkedList is empty

public E getLast()

Returns the last element in this LinkedList.

Returns

  • the last element

Throws

NoSuchElementException when this LinkedList is empty

public int indexOf(Object object)

Searches this LinkedList for the specified object and returns the index of the first occurrence.

Parameters

object the object to search for

Returns

  • the index of the first occurrence of the object

public int lastIndexOf(Object object)

Searches this LinkedList for the specified object and returns the index of the last occurrence.

Parameters

object the object to search for

Returns

  • the index of the last occurrence of the object

public ListIterator<E> listIterator(int location)

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.

Parameters

location the index at which to start the iteration

Returns

  • a ListIterator on the elements of this LinkedList

Throws

IndexOutOfBoundsException when location < 0 || >= size()

See Also

public boolean offer(E o)

Inserts the specified element into the queue provided that the condition allows such an operation. The method is generally preferable to the collection.add(E), since the latter might throw an exception if the operation fails.

public E peek()

Gets but not removes the element in the head of the queue, or throws exception if there is no element in the queue.

public E poll()

Gets and removes the element in the head of the queue, or returns null if there is no element in the queue.

public E remove(int location)

Removes the object at the specified location from this LinkedList.

Parameters

location the index of the object to remove

Returns

  • the removed object

Throws

IndexOutOfBoundsException when location < 0 || >= size()

public E remove()

Gets and removes the element in the head of the queue. Throws a NoSuchElementException if there is no element in the queue.

public boolean remove(Object object)

Removes the first occurrence of the specified object from this Collection. This operation traverses over the collection, looking for the specified object. Once the object is found, the object will be removed from the collection using the iterator's remove method. This collection will throw an UnsupportedOperationException if the iterator returned does not implement remove method, and the specified object is in this collection.

Parameters

object the object to remove

Returns

  • true if this Collection is modified, false otherwise

public E removeFirst()

Removes the first object from this LinkedList.

Returns

  • the removed object

Throws

NoSuchElementException when this LinkedList is empty

public E removeLast()

Removes the last object from this LinkedList.

Returns

  • the removed object

Throws

NoSuchElementException when this LinkedList is empty

public E set(int location, E object)

Replaces the element at the specified location in this LinkedList with the specified object.

Parameters

location the index at which to put the specified object
object the object to add

Returns

  • the previous element at the index

Throws

IndexOutOfBoundsException when location < 0 || >= size()

public int size()

Returns the number of elements in this LinkedList.

Returns

  • the number of elements in this LinkedList

public T[] toArray(T[] contents)

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.

Parameters

contents the array

Returns

  • an array of the elements from this LinkedList

Throws

ArrayStoreException when the type of an element in this LinkedList cannot be stored in the type of the specified array

public Object[] toArray()

Returns a new array containing all elements contained in this LinkedList.

Returns

  • an array of the elements from this LinkedList
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56