CopyOnWriteArrayList Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.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 ISequencedCollection
interface IRandomAccess
- Inheritance
- 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
| Name | Description |
|---|---|
| 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
| Name | Description |
|---|---|
| Class |
Returns the runtime class of this |
| First |
Gets the first element of this collection. |
| Handle |
The handle to the underlying Android instance. (Inherited from Object) |
| IsEmpty |
Returns |
| JniIdentityHashCode |
Gets the identity hash code assigned to this Java peer by the interop runtime. (Inherited from Object) |
| JniManagedPeerState | (Inherited from JavaObject) |
| JniPeerMembers | |
| Last |
Gets the last element of this collection. |
| PeerReference |
Gets the JNI object reference for this Java peer. (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
| Name | Description |
|---|---|
| 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. |
| AddFirst(Object) |
Adds an element as the first element of this collection (optional operation). |
| AddIfAbsent(Object) |
Appends the element, if not present. |
| AddLast(Object) |
Adds an element as the last element of this collection (optional operation). |
| Clear() |
Removes all of the elements from this list. |
| Clone() |
Returns a shallow copy of this list. |
| Construct(JniObjectReference, JniObjectReferenceOptions) | (Inherited from JavaObject) |
| Contains(Object) |
Returns |
| ContainsAll(ICollection) |
Returns |
| Dispose() |
Releases the resources held by this Java peer. (Inherited from Object) |
| Dispose(Boolean) |
Releases the resources held by this Java peer. (Inherited from Object) |
| DisposeUnlessReferenced() | (Inherited from JavaObject) |
| Equals(Object) | (Inherited from JavaObject) |
| Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
| ForEach(IConsumer) |
Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception. |
| Get(Int32) |
Returns the element at the specified position in this list. |
| 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 |
| IndexOf(Object) |
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. |
| Iterator() |
Returns an iterator over the elements in this list in proper sequence. |
| JavaFinalize() |
Obsolete.
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 |
| LastIndexOf(Object) |
Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. |
| ListIterator() |
Returns a list iterator over the elements in this list (in proper sequence). |
| ListIterator(Int32) |
Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. |
| 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. |
| RemoveFirst() |
Removes and returns the first element of this collection (optional operation). |
| RemoveIf(IPredicate) |
Removes all of the elements of this collection that satisfy the given predicate. |
| RemoveLast() |
Removes and returns the last element of this collection (optional operation). |
| ReplaceAll(IUnaryOperator) | |
| RetainAll(ICollection) |
Retains only the elements in this list that are contained in the specified collection. |
| Reversed() |
Returns a reverse-ordered view of this 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) |
| SetPeerReference(JniObjectReference, JniObjectReferenceOptions) | (Inherited from JavaObject) |
| Size() |
Returns the number of elements in this list. |
| Sort(IComparator) | |
| Spliterator() |
Returns a |
| SubList(Int32, Int32) |
Returns a view of the portion of this list between
|
| 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>() |
Creates a managed array from this Java array wrapper. (Inherited from Object) |
| ToString() |
Returns a string representation of the object. (Inherited from Object) |
| UnregisterFromRuntime() |
Unregisters this Java peer from the interop runtime. (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
| Name | Description |
|---|---|
| IJavaPeerable.Disposed() | (Inherited from JavaObject) |
| IJavaPeerable.Finalized() | (Inherited from JavaObject) |
| IJavaPeerable.JniObjectReferenceControlBlock | (Inherited from JavaObject) |
| IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from JavaObject) |
| IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from JavaObject) |
| IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from JavaObject) |
| IJavaPeerable.UnregisterFromRuntime() | |
Extension Methods
| Name | Description |
|---|---|
| GetJniTypeName(IJavaPeerable) |
Gets the JNI name of the type of the instance |
| JavaAs<TResult>(IJavaPeerable) |
Try to coerce |
| JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
| JavaCast<TResult>(IJavaObject) | |
| ToEnumerable(IIterable) |
Returns an IEnumerable that iterates over a Java
IIterable, allowing |
| ToEnumerable<T>(IIterable) |
Returns an IEnumerable<T> that iterates over a Java
IIterable, marshaling each element to |
| TryJavaCast<TResult>(IJavaPeerable, TResult) |
Try to coerce |