Compartilhar via


CopyOnWriteArrayList Class

Definition

A thread-safe variant of java.util.ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array.

[Android.Runtime.Register("java/util/concurrent/CopyOnWriteArrayList", DoNotGenerateAcw=true)]
[Java.Interop.JavaTypeParameters(new System.String[] { "E" })]
public class CopyOnWriteArrayList : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable, Java.Lang.ICloneable, Java.Util.IList, Java.Util.IRandomAccess
[<Android.Runtime.Register("java/util/concurrent/CopyOnWriteArrayList", DoNotGenerateAcw=true)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "E" })>]
type CopyOnWriteArrayList = class
    inherit Object
    interface ISerializable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface ICloneable
    interface IList
    interface ICollection
    interface IIterable
    interface IRandomAccess
Inheritance
CopyOnWriteArrayList
Attributes
Implements

Remarks

A thread-safe variant of java.util.ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array.

This is ordinarily too costly, but may be <em>more</em> efficient than alternatives when traversal operations vastly outnumber mutations, and is useful when you cannot or don't want to synchronize traversals, yet need to preclude interference among concurrent threads. The "snapshot" style iterator method uses a reference to the state of the array at the point that the iterator was created. This array never changes during the lifetime of the iterator, so interference is impossible and the iterator is guaranteed not to throw ConcurrentModificationException. The iterator will not reflect additions, removals, or changes to the list since the iterator was created. Element-changing operations on iterators themselves (remove, set, and add) are not supported. These methods throw UnsupportedOperationException.

All elements are permitted, including null.

Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a CopyOnWriteArrayList<i>happen-before</i> actions subsequent to the access or removal of that element from the CopyOnWriteArrayList in another thread.

This class is a member of the Java Collections Framework.

Added in 1.5.

Java documentation for java.util.concurrent.CopyOnWriteArrayList.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

CopyOnWriteArrayList()

Creates an empty list.

CopyOnWriteArrayList(ICollection)

Creates a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

CopyOnWriteArrayList(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

CopyOnWriteArrayList(Object[])

Creates a list holding a copy of the given array.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsEmpty

Returns true if this list contains no elements.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Add(Int32, Object)

Inserts the specified element at the specified position in this list.

Add(Object)

Appends the specified element to the end of this list.

AddAll(ICollection)

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.

AddAll(Int32, ICollection)

Inserts all of the elements in the specified collection into this list, starting at the specified position.

AddAllAbsent(ICollection)

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.

AddIfAbsent(Object)

Appends the element, if not present.

Clear()

Removes all of the elements from this list.

Clone()

Returns a shallow copy of this list.

Contains(Object)

Returns true if this list contains the specified element.

ContainsAll(ICollection)

Returns true if this list contains all of the elements of the specified collection.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
ForEach(IConsumer)
Get(Int32)

To be added

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
IndexOf(Object, Int32)

Returns the index of the first occurrence of the specified element in this list, searching forwards from index, or returns -1 if the element is not found.

IndexOf(Object)

To be added

Iterator()

Returns an iterator over the elements in this list in proper sequence.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
LastIndexOf(Object, Int32)

Returns the index of the last occurrence of the specified element in this list, searching backwards from index, or returns -1 if the element is not found.

LastIndexOf(Object)

To be added

ListIterator()

To be added

ListIterator(Int32)

To be added

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Remove(Int32)

Removes the element at the specified position in this list.

Remove(Object)

Removes the first occurrence of the specified element from this list, if it is present.

RemoveAll(ICollection)

Removes from this list all of its elements that are contained in the specified collection.

RemoveIf(IPredicate)
ReplaceAll(IUnaryOperator)
RetainAll(ICollection)

Retains only the elements in this list that are contained in the specified collection.

Set(Int32, Object)

Replaces the element at the specified position in this list with the specified element.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
Size()

Returns the number of elements in this list.

Sort(IComparator)
Spliterator()

Returns a Spliterator over the elements in this list.

SubList(Int32, Int32)

Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive.

ToArray()

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

ToArray(Object[])

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)
ToEnumerable(IIterable)
ToEnumerable<T>(IIterable)

Applies to