Google is committed to advancing racial equity for Black communities. See how.

MutableVector

class MutableVector<T> : RandomAccess
kotlin.Any
   ↳ androidx.compose.runtime.collection.MutableVector

A MutableList-like structure with a simplified interface that offers faster access than ArrayList.

Summary

Public methods
Boolean
add(element: T)

Adds element to the MutableVector and returns true.

Unit
add(index: Int, element: T)

Adds element to the MutableVector at the given index, shifting over any elements that are in the way.

Boolean
addAll(index: Int, elements: List<T>)

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

Boolean
addAll(index: Int, elements: MutableVector<T>)

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

Boolean
addAll(elements: List<T>)

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

Boolean
addAll(elements: MutableVector<T>)

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

Boolean
addAll(elements: Array<T>)

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

Boolean
addAll(index: Int, elements: Collection<T>)

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

Boolean
addAll(elements: Collection<T>)

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

Boolean
any(predicate: (T) -> Boolean)

Returns true if any of the elements give a true return value for predicate.

MutableList<T>

Returns MutableList interface access to the MutableVector.

Unit

Removes all elements in the MutableVector.

operator Boolean
contains(element: T)

Returns true if the MutableVector contains element or false otherwise.

Boolean
containsAll(elements: List<T>)

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

Boolean
containsAll(elements: Collection<T>)

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

Boolean
containsAll(elements: MutableVector<T>)

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

Boolean

Returns true if the contents of the MutableVector are the same or false if there is any difference.

Unit
ensureCapacity(capacity: Int)

Ensures that there is enough space to store capacity elements in the MutableVector.

T

Returns the first element in the MutableVector or throws a NoSuchElementException if it isEmpty.

T
first(predicate: (T) -> Boolean)

Returns the first element in the MutableVector for which predicate returns true or throws NoSuchElementException if nothing matches.

T?

Returns the first element in the MutableVector or null if it isEmpty.

T?
firstOrNull(predicate: (T) -> Boolean)

Returns the first element in the MutableVector for which predicate returns true or returns null if nothing matches.

R
fold(initial: R, operation: (acc: R, T) -> R)

Accumulates values, starting with initial, and applying operation to each element in the MutableVector in order.

R
foldIndexed(initial: R, operation: (index: Int, acc: R, T) -> R)

Accumulates values, starting with initial, and applying operation to each element in the MutableVector in order.

R
foldRight(initial: R, operation: (T, acc: R) -> R)

Accumulates values, starting with initial, and applying operation to each element in the MutableVector in reverse order.

R
foldRightIndexed(initial: R, operation: (index: Int, T, acc: R) -> R)

Accumulates values, starting with initial, and applying operation to each element in the MutableVector in reverse order.

Unit
forEach(block: (T) -> Unit)

Calls block for each element in the MutableVector, in order.

Unit
forEachIndexed(block: (Int, T) -> Unit)

Calls block for each element in the MutableVector along with its index, in order.

Unit
forEachReversed(block: (T) -> Unit)

Calls block for each element in the MutableVector in reverse order.

Unit
forEachReversedIndexed(block: (Int, T) -> Unit)

Calls block for each element in the MutableVector along with its index, in reverse order.

operator T
get(index: Int)

Returns the element at the given index.

Int
indexOf(element: T)

Returns the index of element in the MutableVector or -1 if element is not there.

Int
indexOfFirst(predicate: (T) -> Boolean)

Returns the index if the first element in the MutableVector for which predicate returns true.

Int
indexOfLast(predicate: (T) -> Boolean)

Returns the index if the last element in the MutableVector for which predicate returns true.

Boolean

Returns true if the MutableVector has no elements in it or false otherwise.

Boolean

Returns true if there are elements in the MutableVector or false if it is empty.

T

Returns the last element in the MutableVector or throws a NoSuchElementException if it isEmpty.

T
last(predicate: (T) -> Boolean)

Returns the last element in the MutableVector for which predicate returns true or throws NoSuchElementException if nothing matches.

Int
lastIndexOf(element: T)

Returns the index of the last element in the MutableVector that is the same as element or -1 if no elements match.

T?

Returns the last element in the MutableVector or null if it isEmpty.

T?
lastOrNull(predicate: (T) -> Boolean)

Returns the last element in the MutableVector for which predicate returns true or returns null if nothing matches.

Array<R>
map(transform: (T) -> R)

Returns an Array of results of transforming each element in the MutableVector.

Array<R>
mapIndexed(transform: (index: Int, T) -> R)

Returns an Array of results of transforming each element in the MutableVector.

MutableVector<R>
mapIndexedNotNull(transform: (index: Int, T) -> R?)

Returns an MutableVector of results of transforming each element in the MutableVector, excluding those transformed values that are null.

MutableVector<R>
mapNotNull(transform: (T) -> R?)

Returns an MutableVector of results of transforming each element in the MutableVector, excluding those transformed values that are null.

operator Unit
minusAssign(element: T)

remove from the MutableVector

operator Unit
plusAssign(element: T)

add to the MutableVector.

Boolean
remove(element: T)

Removes element from the MutableVector.

Boolean
removeAll(elements: List<T>)

Removes all elements from the MutableVector and returns true if anything was removed.

Boolean
removeAll(elements: MutableVector<T>)

Removes all elements from the MutableVector and returns true if anything was removed.

Boolean
removeAll(elements: Collection<T>)

Removes all elements from the MutableVector and returns true if anything was removed.

T
removeAt(index: Int)

Removes the element at the given index and returns it.

Unit
removeRange(start: Int, end: Int)

Removes items from index start (inclusive) to end (exclusive).

Boolean
retainAll(elements: Collection<T>)

Keeps only elements in the MutableVector and removes all other values.

Boolean
reversedAny(predicate: (T) -> Boolean)

Returns true if any of the elements give a true return value for predicate while iterating in the reverse order.

operator T
set(index: Int, element: T)

Sets the value at index to element.

Unit
sortWith(comparator: Comparator<T>)

Sorts the MutableVector using comparator to order the items.

Int
sumBy(selector: (T) -> Int)

Returns the sum of all values produced by selector for each element in the MutableVector.

Properties
IntRange

Returns an IntRange of the valid indices for this MutableVector.

Int

Returns the last valid index in the MutableVector.

Int

The number of elements in the MutableVector.

Public methods

add

fun add(element: T): Boolean

Adds element to the MutableVector and returns true.

add

fun add(
    index: Int,
    element: T
): Unit

Adds element to the MutableVector at the given index, shifting over any elements that are in the way.

addAll

fun addAll(
    index: Int,
    elements: List<T>
): Boolean

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

addAll

fun addAll(
    index: Int,
    elements: MutableVector<T>
): Boolean

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

addAll

inline fun addAll(elements: List<T>): Boolean

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

addAll

inline fun addAll(elements: MutableVector<T>): Boolean

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

addAll

fun addAll(elements: Array<T>): Boolean

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

addAll

fun addAll(
    index: Int,
    elements: Collection<T>
): Boolean

Adds all elements to the MutableVector at the given index, shifting over any elements that are in the way.

addAll

fun addAll(elements: Collection<T>): Boolean

Adds all elements to the end of the MutableVector and returns true if the MutableVector was changed.

any

inline fun any(predicate: (T) -> Boolean): Boolean

Returns true if any of the elements give a true return value for predicate.

asMutableList

fun asMutableList(): MutableList<T>

Returns MutableList interface access to the MutableVector.

clear

fun clear(): Unit

Removes all elements in the MutableVector.

contains

operator fun contains(element: T): Boolean

Returns true if the MutableVector contains element or false otherwise.

containsAll

fun containsAll(elements: List<T>): Boolean

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

containsAll

fun containsAll(elements: Collection<T>): Boolean

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

containsAll

fun containsAll(elements: MutableVector<T>): Boolean

Returns true if the MutableVector contains all elements in elements or false if one or more are missing.

contentEquals

fun contentEquals(other: MutableVector<T>): Boolean

Returns true if the contents of the MutableVector are the same or false if there is any difference. This uses equality comparisons on each element rather than reference equality.

ensureCapacity

fun ensureCapacity(capacity: Int): Unit

Ensures that there is enough space to store capacity elements in the MutableVector.

first

fun first(): T

Returns the first element in the MutableVector or throws a NoSuchElementException if it isEmpty.

first

inline fun first(predicate: (T) ->