CopyOnWriteArrayList
open class CopyOnWriteArrayList<E : Any!> : Cloneable, MutableList<E>, RandomAccess, Serializable
| kotlin.Any | |
| ↳ | java.util.concurrent.CopyOnWriteArrayList |
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 more 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 happen-before 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.
Summary
| Public constructors | |
|---|---|
|
Creates an empty list. |
|
CopyOnWriteArrayList(toCopyIn: Array<E>)Creates a list holding a copy of the given array. |
|
CopyOnWriteArrayList(c: MutableCollection<out E>)Creates a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. |
|
| Public methods | |
|---|---|
| open Boolean |
add(element: E)Appends the specified element to the end of this list. |
| open Unit |
Inserts the specified element at the specified position in this list. |
| open Boolean |
addAll(index: Int, elements: Collection<E>)Inserts all of the elements in the specified collection into this list, starting at the specified position. |
| open Boolean |
addAll(elements: Collection<E>)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. |
| open Int |
addAllAbsent(c: MutableCollection<out E>)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. |
| open Unit |
addFirst(e: E)Adds an element as the first element of this collection (optional operation). |
| open Boolean |
addIfAbsent(e: E)Appends the element, if not present. |
| open Unit |
addLast(e: E)Adds an element as the last element of this collection (optional operation). |
| open Unit |
clear()Removes all of the elements from this list. |
| open Any |
clone()Returns a shallow copy of this list. |
| open Boolean |
contains(element: E?)Returns |
| open Boolean |
containsAll(elements: Collection<E>)Returns |
| open Boolean |
Compares the specified object with this list for equality. |
| open Unit | |
| open E |
Returns the element at the specified position in this list. |
| open E |
getFirst()Gets the first element of this collection. |
| open E |
getLast()Gets the last element of this collection. |
| open Int |
hashCode()Returns the hash code value for this list. |
| open Int |
Returns the index of the first occurrence of the specified element in this list, searching forwards from |
| open Int |
indexOf(element: E?)Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. |
| open Boolean |
isEmpty()Returns |
| open MutableIterator<E> |
iterator()Returns an iterator over the elements in this list in proper sequence. |
| open Int |
lastIndexOf(e: E?, index: Int)Returns the index of the last occurrence of the specified element in this list, searching backwards from |
| open Int |
lastIndexOf(element: E?)Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. |
| open MutableListIterator<E> |
Returns a list iterator over the elements in this list (in proper sequence). |
| open MutableListIterator<E> |
listIterator(index: Int)Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. |
| open Boolean |
remove(element: E?)Removes the first occurrence of the specified element from this list, if it is present. |
| open Boolean |
removeAll(elements: Collection<E>)Removes from this list all of its elements that are contained in the specified collection. |
| open E |
Removes the element at the specified position in this list. |
| open E |
Removes and returns the first element of this collection (optional operation). |
| open Boolean | |
| open E |
Removes and returns the last element of this collection (optional operation). |
| open Unit |
replaceAll(operator: UnaryOperator<E>)Replaces each element of this list with the result of applying the operator to that element (optional operation). |
| open Boolean |
retainAll(elements: Collection<E>)Retains only the elements in this list that are contained in the specified collection. |
| open MutableList<E> |
reversed()Returns a reverse-ordered view of this collection. |
| open E |
Replaces the element at the specified position in this list with the specified element. |
| open Unit |
sort(c: Comparator<in E>?)Sorts this list according to the order induced by the specified |
| open Spliterator<E> |
Returns a |
| open MutableList<E> |
Returns a view of the portion of this list between |
| open Array<Any!> |
toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element). |
| open Array<T> |
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. |
| open String |
toString()Returns a string representation of this list. |
| Properties | |
|---|---|
| open Int |
Returns the number of elements in this list. |
Public constructors
CopyOnWriteArrayList
CopyOnWriteArrayList(toCopyIn: Array<E>)
Creates a list holding a copy of the given array.
| Parameters | |
|---|---|
toCopyIn |
Array<E>: the array (a copy of this array is used as the internal array) |
| Exceptions | |
|---|---|
java.lang.NullPointerException |
if the specified array is null |
CopyOnWriteArrayList
CopyOnWriteArrayList(c: MutableCollection<out E>)
Creates a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
| Parameters | |
|---|---|
c |
MutableCollection<out E>: the collection of initially held elements |
| Exceptions | |
|---|---|
java.lang.NullPointerException |
if the specified collection is null |
Public methods
add
open fun add(element: E): Boolean
Appends the specified element to the end of this list.
| Parameters | |
|---|---|
e |
element to be appended to this list |
| Return | |
|---|---|
Boolean |
true (as specified by Collection.add) |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the class of the specified element prevents it from being added to this list |
java.lang.IllegalArgumentException |
if some property of this element prevents it from being added to this list |
java.lang.IllegalStateException |
if the element cannot be added at this time due to insertion restrictions |
java.lang.NullPointerException |
if the specified element is null and this list does not permit null elements |
java.lang.UnsupportedOperationException |
if the add operation is not supported by this list |
add
open fun add(
index: Int,
element: E
): Unit
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
| Parameters | |
|---|---|
index |
Int: index at which the specified element is to be inserted |
element |
E: element to be inserted |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the class of the specified element prevents it from being added to this list |
java.lang.IllegalArgumentException |
if some property of the specified element prevents it from being added to this list |
java.lang.IndexOutOfBoundsException |
if the index is out of range (index < 0 || index > size()) |
java.lang.NullPointerException |
if the specified element is null and this list does not permit null elements |
java.lang.UnsupportedOperationException |
if the add operation is not supported by this list |
addAll
open fun addAll(
index: Int,
elements: Collection<E>
): Boolean
Inserts all of the elements in the specified collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new