ArrayList

open actual class ArrayList<E> : 
    AbstractMutableList<E>,
    MutableList<E>,
    RandomAccess
(source)

Platform and version requirements: JS

Provides a MutableList implementation, which uses a resizable array as its backing storage.

This implementation doesn't provide a way to manage capacity, as backing JS array is resizeable itself. There is no speed advantage to pre-allocating array sizes in JavaScript, so this implementation does not include any of the capacity and "growth increment" concepts.

Constructors

<init>

ArrayList()
ArrayList(initialCapacity: Int = 0)

Creates an empty ArrayList.

ArrayList(elements: Collection<E>)

Creates an ArrayList filled from the elements collection.

Properties

size

open actual val size: Int

Returns the size of the collection.

Inherited Properties

modCount

var modCount: Int

Functions

add

open actual fun add(element: E): Boolean

Adds the specified element to the collection.

open actual fun add(index: Int, element: E)

Inserts an element into the list at the specified index.

addAll

open actual fun addAll(elements: Collection<E>): Boolean

Adds all of the elements in the specified collection to this collection.

open actual fun addAll(
    index: Int,
    elements: Collection<E>
): Boolean

Inserts all of the elements in the specified collection elements into this list at the specified index.

clear

open actual fun clear()

Removes all elements from this collection.

ensureCapacity

actual fun ensureCapacity(minCapacity: Int)

Does nothing in this ArrayList implementation.

get

open actual fun get(index: Int): E

Returns the element at the specified index in the list.

indexOf

open actual fun indexOf(element: E): Int

Returns the index of the first occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.

lastIndexOf

open actual fun lastIndexOf(element: E): Int

Returns the index of the last occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.

remove

open actual fun remove(element: E): Boolean

Removes a single instance of the specified element from this collection, if it is present.

removeAt

open actual fun removeAt(index: Int): E

Removes an element at the specified index from the list.

removeRange

open fun removeRange(fromIndex: Int, toIndex: Int)

Removes the range of elements from this list starting from fromIndex and ending with but not including toIndex.

set

open actual fun set(index: Int, element: E): E

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

toArray

open fun toArray(): Array<Any?>

toString

open fun toString(): String

Returns a string representation of the object.

trimToSize

actual fun trimToSize()

Does nothing in this ArrayList implementation.

Inherited Functions

contains

open actual fun contains(element: E): Boolean

Checks if the specified element is contained in this collection.

containsAll

open fun containsAll(elements: Collection<E>): Boolean

Checks if all elements in the specified collection are contained in this collection.

equals

open fun equals(other: Any?): Boolean

Compares this list with another list instance with the ordered structural equality.

hashCode

open fun hashCode(): Int

Returns the hash code value for this list.

isEmpty

open fun isEmpty(): Boolean

Returns true if the collection is empty (contains no elements), false otherwise.

iterator

open actual fun iterator(): MutableIterator<E>

Returns an iterator over the elements of this object.

listIterator

open actual fun listIterator(): MutableListIterator<E>

Returns a list iterator over the elements in this list (in proper sequence).

open actual fun listIterator(
    index: Int
): MutableListIterator<E>

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified index.

removeAll

open actual fun removeAll(elements: Collection<E>): Boolean

Removes all of this collection's elements that are also contained in the specified collection.

retainAll

open actual fun retainAll(elements: Collection<E>): Boolean

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

subList

open actual fun subList(
    fromIndex: Int,
    toIndex: Int
): MutableList<E>

Returns a view of the portion of this list between the specified fromIndex (inclusive) and toIndex (exclusive). The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.