Android
java.util.concurrent
public class

java.util.concurrent.CopyOnWriteArrayList<E>

java.lang.Object
java.util.concurrent.CopyOnWriteArrayList<E> Serializable Cloneable List<E> RandomAccess

Implements a ArrayList variant that is thread-safe. All write operation result in a new copy of the underlying data being created. Iterators reflect the state of the CopyOnWriteArrayList at the time they were created. They are not updated to reflect subsequent changes to the list. In addition, these iterators cannot be used for modifying the underlying CopyOnWriteArrayList.

Summary

Public Constructors

            CopyOnWriteArrayList()
Creates a new, empty instance of CopyOnWriteArrayList.
            CopyOnWriteArrayList(Collection<? extends E> c)
Creates a new instance of CopyOnWriteArrayList and fills it with the contents of a given Collection.
            CopyOnWriteArrayList(E[] array)
Creates a new instance of CopyOnWriteArrayList and fills it with the contents of a given array.

Public Methods

          void  add(int index, E e)
Inserts the specified object into this Vector at the specified location.
          boolean  add(E e)
Adds the specified object at the end of this List.
          boolean  addAll(int index, Collection<? extends E> c)
Inserts the objects in the specified Collection at the specified location in this List.
          boolean  addAll(Collection<? extends E> c)
Adds the objects in the specified Collection to the end of this List.
          int  addAllAbsent(Collection<? extends E> c)
Adds to this CopyOnWriteArrayList all those elements from a given collection that are not yet part of the list.
          boolean  addIfAbsent(E e)
Adds to this CopyOnWriteArrayList another element, given that this element is not yet part of the list.
          void  clear()
Removes all elements from this List, leaving it empty.
          Object  clone()
Returns a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.
          boolean  contains(Object o)
Searches this List for the specified object.
          boolean  containsAll(Collection<?> c)
Searches this List for all objects in the specified Collection.
          boolean  equals(Object o)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
          get(int index)
Returns the element at the specified location in this List.
          int  hashCode()
Returns an integer hash code for the receiver.
          int  indexOf(E e, int index)
Returns the index of a given element, starting the search from a given position in the list.
          int  indexOf(Object o)
Searches this List for the specified object and returns the index of the first occurrence.
          boolean  isEmpty()
Returns if this List has no elements, a size of zero.
          Iterator<E>  iterator()
Returns an Iterator on the elements of this List.
          int  lastIndexOf(E e, int index)
Returns the last index of a given element, starting the search from a given position in the list and going backwards.
          int  lastIndexOf(Object o)
Searches this List for the specified object and returns the index of the last occurrence.
          ListIterator<E>  listIterator()
Returns a ListIterator on the elements of this List.
          ListIterator<E>  listIterator(int index)
Returns a ListIterator on the elements of this List.
          remove(int index)
Removes the object at the specified location from this List.
          boolean  remove(Object o)
Removes the first occurrence of the specified object from this List.
          boolean  removeAll(Collection<?> c)
Removes all occurrences in this List of each object in the specified Collection.
          boolean  retainAll(Collection<?> c)
Removes all objects from this List that are not contained in the specified Collection.
          set(int index, E e)
Replaces the element at the specified location in this List with the specified object.
          int  size()
Returns the number of elements in this List.
          List<E>  subList(int fromIndex, int toIndex)
Returns a List of the specified portion of this List from the start index to one less than the end index.
        <T>  T[]  toArray(T[] a)
Returns an array containing all elements contained in this List.
          Object[]  toArray()
Returns an array containing all elements contained in this List.
          String  toString()
Returns a string containing a concise, human-readable description of the receiver.
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

Details

Public Constructors

public CopyOnWriteArrayList()

Creates a new, empty instance of CopyOnWriteArrayList.

public CopyOnWriteArrayList(Collection<? extends E> c)

Creates a new instance of CopyOnWriteArrayList and fills it with the contents of a given Collection.

Parameters

c the collection the elements of which are to be copied into the new instance.

public CopyOnWriteArrayList(E[] array)

Creates a new instance of CopyOnWriteArrayList and fills it with the contents of a given array.

Parameters

array the array the elements of which are to be copied into the new instance.

Public Methods

public void add(int index, E e)

Inserts the specified object into this Vector 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 List, the object is added at the end.

public boolean add(E e)

Adds the specified object at the end of this List.

public boolean addAll(int index, Collection<? extends E> c)

Inserts the objects in the specified Collection at the specified location in this List. The objects are added in the order they are returned from the Collection iterator.

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

Adds the objects in the specified Collection to the end of this List. The objects are added in the order they are returned from the Collection iterator.

public int addAllAbsent(Collection<? extends E> c)

Adds to this CopyOnWriteArrayList all those elements from a given collection that are not yet part of the list.

Parameters

c the collection from which the potential new elements are taken.

Returns

  • the number of elements actually added to this list.

public boolean addIfAbsent(E e)

Adds to this CopyOnWriteArrayList another element, given that this element is not yet part of the list.

Parameters

e the potential new element.

Returns

  • true if the element was added, or false otherwise.

public void clear()

Removes all elements from this List, leaving it empty.

public Object clone()

Returns a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.

Classes which wish to support cloning must specify that they implement the Cloneable interface, since the implementation checks for this.

Returns

  • Object a shallow copy of this object.

public boolean contains(Object o)

Searches this List for the specified object.

public boolean containsAll(Collection<?> c)

Searches this List for all objects in the specified Collection.

public boolean equals(Object o)

Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison. The implementation in Object returns true only if the argument is the exact same object as the receiver (==).

Parameters

o Object the object to compare with this object.

Returns

  • boolean true if the object is the same as this object false if it is different from this object.

public E get(int index)

Returns the element at the specified location in this List.

public int hashCode()

Returns an integer hash code for the receiver. Any two objects which answer true when passed to .equals must answer the same value for this method.

Returns

  • int the receiver's hash.

public int indexOf(E e, int index)

Returns the index of a given element, starting the search from a given position in the list.

Parameters

e the element to search.
index the index at which to start the search.

Returns

  • the index of the element or null, if the element has not been found at or beyond the given start index.

public int indexOf(Object o)

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

public boolean isEmpty()

Returns if this List has no elements, a size of zero.

public Iterator<E> iterator()

Returns an Iterator on the elements of this List. The elements are iterated in the same order that they occur in the List.

public int lastIndexOf(E e, int index)

Returns the last index of a given element, starting the search from a given position in the list and going backwards.

Parameters

e the element to search.
index the index at which to start the search.

Returns

  • the index of the element or null, if the element has not been found at or before the given start index.

public int lastIndexOf(Object o)

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

public ListIterator<E> listIterator()

Returns a ListIterator on the elements of this List. The elements are iterated in the same order that they occur in the List.

public ListIterator<E> listIterator(int index)

Returns a ListIterator on the elements of this List. The elements are iterated in the same order that they occur in the List. The iteration starts at the specified location.

public E remove(int index)

Removes the object at the specified location from this List.

public boolean remove(Object o)

Removes the first occurrence of the specified object from this List.

public boolean removeAll(Collection<?> c)

Removes all occurrences in this List of each object in the specified Collection.

public boolean retainAll(Collection<?> c)

Removes all objects from this List that are not contained in the specified Collection.

public E set(int index, E e)

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

public int size()

Returns the number of elements in this List.

public List<E> subList(int fromIndex, int toIndex)

Returns a List of the specified portion of this List from the start index to one less than the end index. The returned List is backed by this list so changes to one are reflected by the other.

public T[] toArray(T[] a)

Returns an array containing all elements contained in this List. 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 List, the array element following the collection elements is set to null.

public Object[] toArray()

Returns an array containing all elements contained in this List.

public String toString()

Returns a string containing a concise, human-readable description of the receiver.

Returns

  • String a printable representation for the receiver.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56