|
Préférences
Moteurs de recherche
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.5.0
java.util.concurrent
|
Constructor Summary | |
---|---|
CopyOnWriteArrayList()
Creates an empty list. |
|
CopyOnWriteArrayList(Collection<? extends E> c)
Creates a list containing the elements of the specified Collection, in the order they are returned by the Collection's iterator. |
|
CopyOnWriteArrayList(E[] toCopyIn)
Create a new CopyOnWriteArrayList holding a copy of given array. |
Method Summary | ||
---|---|---|
boolean |
add(E element)
Appends the specified element to the end of this list. |
|
void |
add(int index,
E element)
Inserts the specified element at the specified position in this list. |
|
boolean |
addAll(Collection<? extends E> c)
Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator. |
|
boolean |
addAll(int index,
Collection<? extends E> c)
Inserts all of the elements in the specified Collection into this list, starting at the specified position. |
|
int |
addAllAbsent(Collection<? extends E> c)
Appends all of the elements in the specified Collection that are not already contained in this list, to the end of this list, in the order that they are returned by the specified Collection's Iterator. |
|
boolean |
addIfAbsent(E element)
Append the element if not present. |
|
void |
clear()
Removes all of the elements from this list. |
|
Object |
clone()
Returns a shallow copy of this list. |
|
boolean |
contains(Object elem)
Returns true if this list contains the specified element. |
|
boolean |
containsAll(Collection<?> c)
Returns true if this Collection contains all of the elements in the specified Collection. |
|
boolean |
equals(Object o)
Compares the specified Object with this List for equality. |
|
E |
get(int index)
Returns the element at the specified position in this list. |
|
int |
hashCode()
Returns the hash code value for this List. |
|
int |
indexOf(E elem,
int index)
Searches for the first occurrence of the given argument, beginning the search at index, and testing for equality using the equals method. |
|
int |
indexOf(Object elem)
Searches for the first occurrence of the given argument, testing for equality using the equals method. |
|
boolean |
isEmpty()
Tests if this list has no elements. |
|
Iterator<E> |
iterator()
Returns an Iterator over the elements contained in this collection. |
|
int |
lastIndexOf(E elem,
int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it. |
|
int |
lastIndexOf(Object elem)
Returns the index of the last occurrence of the specified object in this list. |
|
ListIterator<E> |
listIterator()
Returns an Iterator of the elements in this List (in proper sequence). |
|
ListIterator<E> |
listIterator(int index)
Returns a ListIterator of the elements in this List (in proper sequence), starting at the specified position in the List. |
|
E |
remove(int index)
Removes the element at the specified position in this list. |
|
boolean |
remove(Object o)
Removes a single instance of the specified element from this list, if it is present (optional operation). |
|
boolean |
removeAll(Collection<?> c)
Removes from this Collection all of its elements that are contained in the specified Collection. |
|
boolean |
retainAll(Collection<?> c)
Retains only the elements in this Collection that are contained in the specified Collection (optional operation). |
|
E |
set(int index,
E element)
Replaces the element at the specified position in this list with the specified element. |
|
int |
size()
Returns the number of elements in this list. |
|
List<E> |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this List between fromIndex, inclusive, and toIndex, exclusive. |
|
Object[] |
toArray()
Returns an array containing all of the elements in this list in the correct order. |
|
|
toArray(T[] a)
Returns an array containing all of the elements in this list in the correct order. |
|
String |
toString()
Returns a string representation of this Collection, containing the String representation of each element. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CopyOnWriteArrayList()
public CopyOnWriteArrayList(Collection<? extends E> c)
c
- the collection of initially held elementspublic CopyOnWriteArrayList(E[] toCopyIn)
toCopyIn
- the array (a copy of this array is used as the
internal array)Method Detail |
---|
public int size()
public boolean isEmpty()
public boolean contains(Object elem)
elem
- element whose presence in this List is to be tested.
true
if the specified element is present;
false
otherwise.public int indexOf(Object elem)
elem
- an object.
Object.equals(Object)
public int indexOf(E elem, int index)
elem
- an object.index
- the index to start searching from.
Object.equals(Object)
public int lastIndexOf(Object elem)
lastIndexOf
in interface List<E>
elem
- the desired element.
public int lastIndexOf(E elem, int index)
elem
- the desired element.index
- the index to start searching from.
public Object clone()
Cloneable
public Object[] toArray()
Arrays.asList(Object[])
public <T> T[] toArray(T[] a)
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.
a
- the array into which the elements of the list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
ArrayStoreException
- the runtime type of a is not a supertype
of the runtime type of every element in this list.public E get(int index)
index
- index of element to return.
IndexOutOfBoundsException
- if index is out of range (index
< 0 || index >= size()).public E set(int index, E element)
index
- index of element to replace.element
- element to be stored at the specified position.
IndexOutOfBoundsException
- if index out of range
(index < 0 || index >= size()).public boolean add(E element)
element
- element to be appended to this list.
public void add(int index, E element)
index
- index at which the specified element is to be inserted.element
- element to be inserted.
IndexOutOfBoundsException
- if index is out of range
(index < 0 || index > size()).public E remove(int index)
index
- the index of the element to removed.
IndexOutOfBoundsException
- if index out of range (index
< 0 || index >= size()).public boolean remove(Object o)
o
- element to be removed from this list, if present.
public boolean addIfAbsent(E element)
element
- element to be added to this Collection, if absent.
public boolean containsAll(Collection<?> c)
This implementation iterates over the specified Collection, checking each element returned by the Iterator in turn to see if it's contained in this Collection. If all elements are so contained true is returned, otherwise false.
containsAll
in interface Collection<E>
containsAll
in interface List<E>
c
- the collection
Collection.contains(Object)
public boolean removeAll(Collection<?> c)
c
- the collection
Collection.remove(Object)
,
Collection.contains(Object)
public boolean retainAll(Collection<?> c)
c
- the collection
Collection.remove(Object)
,
Collection.contains(Object)
public int addAllAbsent(Collection<? extends E> c)
c
- elements to be added into this list.
public void clear()
public boolean addAll(Collection<? extends E> c)
c
- elements to be inserted into this list.
Collection.add(Object)
public boolean addAll(int index, Collection<? extends E> c)
index
- index at which to insert first element
from the specified collection.c
- elements to be inserted into this list.
IndexOutOfBoundsException
- index out of range (index
< 0 || index > size()).public String toString()
public boolean equals(Object o)
This implementation first checks if the specified object is this List. If so, it returns true; if not, it checks if the specified object is a List. If not, it returns false; if so, it iterates over both lists, comparing corresponding pairs of elements. If any comparison returns false, this method returns false. If either Iterator runs out of elements before the other it returns false (as the Lists are of unequal length); otherwise it returns true when the iterations complete.
o
- the Object to be compared for equality with this List.
Object.hashCode()
,
Hashtable
public int hashCode()
This implementation uses the definition in List.hashCode()
.
Object.equals(java.lang.Object)
,
Hashtable
public Iterator<E> iterator()
public ListIterator<E> listIterator()
listIterator
in interface List<E>
public ListIterator<E> listIterator(int index)
listIterator
in interface List<E>
index
- index of first element to be returned from the
ListIterator (by a call to getNext).
IndexOutOfBoundsException
- index is out of range
(index < 0 || index > size()).public List<E> subList(int fromIndex, int toIndex)
The semantics of the List returned by this method become undefined if the backing list (i.e., this List) is structurally modified in any way other than via the returned List. (Structural modifications are those that change the size of the List, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
fromIndex
- low endpoint (inclusive) of the subList.toIndex
- high endpoint (exclusive) of the subList.
IndexOutOfBoundsException
- Illegal endpoint index value
(fromIndex < 0 || toIndex > size || fromIndex > toIndex).