{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

MutableVector

public final class MutableVector<T extends Object>


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

Summary

Public methods

final boolean
add(@NonNull T element)

Adds element to the MutableVector and returns true.

final void
add(int index, @NonNull T element)

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

final boolean
addAll(@NonNull T[] elements)

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

final boolean

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

final boolean
addAll(@NonNull List<@NonNull T> elements)

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

final boolean

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

final boolean
addAll(int index, @NonNull Collection<@NonNull T> elements)

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

final boolean
addAll(int index, @NonNull List<@NonNull T> elements)

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

final boolean
addAll(int index, @NonNull MutableVector<@NonNull T> elements)

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

final boolean
any(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

final @NonNull List<@NonNull T>

Returns MutableList interface access to the MutableVector.

final void

Removes all elements in the MutableVector.

final boolean
contains(@NonNull T element)

Returns true if the MutableVector contains element or false otherwise.

final boolean

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

final boolean

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

final boolean

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

final boolean

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

final void
ensureCapacity(int capacity)

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

final @NonNull T

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

final @NonNull T
first(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

final T

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

final T
firstOrNull(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

final @NonNull R
<R extends Object> fold(
    @NonNull R initial,
    @NonNull Function2<@NonNull acc, @NonNull T, @NonNull R> operation
)

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

final @NonNull R
<R extends Object> foldIndexed(
    @NonNull R initial,
    @NonNull Function3<@NonNull Integer, @NonNull acc, @NonNull T, @NonNull R> operation
)

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

final @NonNull R
<R extends Object> foldRight(
    @NonNull R initial,
    @NonNull Function2<@NonNull T, @NonNull acc, @NonNull R> operation
)

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

final @NonNull R
<R extends Object> foldRightIndexed(
    @NonNull R initial,
    @NonNull Function3<@NonNull Integer, @NonNull T, @NonNull acc, @NonNull R> operation
)

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

final void
forEach(@NonNull Function1<@NonNull T, Unit> block)

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

final void
forEachIndexed(@NonNull Function2<@NonNull Integer, @NonNull T, Unit> block)

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

final void
forEachReversed(@NonNull Function1<@NonNull T, Unit> block)

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

final void
forEachReversedIndexed(
    @NonNull Function2<@NonNull Integer, @NonNull T, Unit> block
)

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

final @NonNull T
get(int index)

Returns the element at the given index.

final @NonNull IntRange

Returns an IntRange of the valid indices for this MutableVector.

final int

Returns the last valid index in the MutableVector.

final int

The number of elements in the MutableVector.

final int
indexOf(@NonNull T element)

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

final int
indexOfFirst(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

final int
indexOfLast(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

final boolean

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

final boolean

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

final @NonNull T

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

final @NonNull T
last(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

final int
lastIndexOf(@NonNull T element)

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

final T

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

final T
lastOrNull(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

final @NonNull R[]
<R extends Object> map(@NonNull Function1<@NonNull T, @NonNull R> transform)

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

final @NonNull R[]
<R extends Object> mapIndexed(
    @NonNull Function2<@NonNull Integer, @NonNull T, @NonNull R> transform
)

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

final @NonNull MutableVector<@NonNull R>
<R extends Object> mapIndexedNotNull(
    @NonNull Function2<@NonNull Integer, @NonNull T, R> transform
)

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

final @NonNull MutableVector<@NonNull R>
<R extends Object> mapNotNull(@NonNull Function1<@NonNull T, R> transform)

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

final void
minusAssign(@NonNull T element)

remove from the MutableVector

final void
plusAssign(@NonNull T element)

add to the MutableVector.

final boolean
remove(@NonNull T element)

Removes element from the MutableVector.

final boolean

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

final boolean
removeAll(@NonNull List<@NonNull T> elements)

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

final boolean

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

final @NonNull T
removeAt(int index)

Removes the element at the given index and returns it.

final void
removeRange(int start, int end)

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

final boolean

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

final boolean
reversedAny(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

final @NonNull T
set(int index, @NonNull T element)

Sets the value at index to element.

final void

Sorts the MutableVector using comparator to order the items.

final int
sumBy(@NonNull Function1<@NonNull T, @NonNull Integer> selector)

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

Public methods

add

public final boolean add(@NonNull T element)

Adds element to the MutableVector and returns true.

add

public final void add(int index, @NonNull T element)

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

addAll

public final boolean addAll(@NonNull T[] elements)

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

addAll

public final boolean addAll(@NonNull Collection<@NonNull T> elements)

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

addAll

public final boolean addAll(@NonNull List<@NonNull T> elements)

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

addAll

public final boolean addAll(@NonNull MutableVector<@NonNull T> elements)

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

addAll

public final boolean addAll(int index, @NonNull Collection<@NonNull T> elements)

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

addAll

public final boolean addAll(int index, @NonNull List<@NonNull T> elements)

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

addAll

public final boolean addAll(int index, @NonNull MutableVector<@NonNull T> elements)

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

any

public final boolean any(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

asMutableList

public final @NonNull List<@NonNull T> asMutableList()

Returns MutableList interface access to the MutableVector.

clear

public final void clear()

Removes all elements in the MutableVector.

contains

public final boolean contains(@NonNull T element)

Returns true if the MutableVector contains element or false otherwise.

containsAll

public final boolean containsAll(@NonNull Collection<@NonNull T> elements)

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

containsAll

public final boolean containsAll(@NonNull List<@NonNull T> elements)

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

containsAll

public final boolean containsAll(@NonNull MutableVector<@NonNull T> elements)

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

contentEquals

public final boolean contentEquals(@NonNull MutableVector<@NonNull T> other)

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

public final void ensureCapacity(int capacity)

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

first

public final @NonNullfirst()

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

first

public final @NonNullfirst(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

firstOrNull

public final T firstOrNull()

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

firstOrNull

public final T firstOrNull(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

fold

public final @NonNull R <R extends Object> fold(
    @NonNull R initial,
    @NonNull Function2<@NonNull acc, @NonNull T, @NonNull R> operation
)

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

foldIndexed

public final @NonNull R <R extends Object> foldIndexed(
    @NonNull R initial,
    @NonNull Function3<@NonNull Integer, @NonNull acc, @NonNull T, @NonNull R> operation
)

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

foldRight

public final @NonNull R <R extends Object> foldRight(
    @NonNull R initial,
    @NonNull Function2<@NonNull T, @NonNull acc, @NonNull R> operation
)

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

foldRightIndexed

public final @NonNull R <R extends Object> foldRightIndexed(
    @NonNull R initial,
    @NonNull Function3<@NonNull Integer, @NonNull T, @NonNull acc, @NonNull R> operation
)

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

forEach

public final void forEach(@NonNull Function1<@NonNull T, Unit> block)

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

forEachIndexed

public final void forEachIndexed(@NonNull Function2<@NonNull Integer, @NonNull T, Unit> block)

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

forEachReversed

public final void forEachReversed(@NonNull Function1<@NonNull T, Unit> block)

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

forEachReversedIndexed

public final void forEachReversedIndexed(
    @NonNull Function2<@NonNull Integer, @NonNull T, Unit> block
)

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

get

public final @NonNullget(int index)

Returns the element at the given index.

getIndices

public final @NonNull IntRange getIndices()

Returns an IntRange of the valid indices for this MutableVector.

getLastIndex

public final int getLastIndex()

Returns the last valid index in the MutableVector.

getSize

public final int getSize()

The number of elements in the MutableVector.

indexOf

public final int indexOf(@NonNull T element)

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

indexOfFirst

public final int indexOfFirst(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

indexOfLast

public final int indexOfLast(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

isEmpty

public final boolean isEmpty()

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

isNotEmpty

public final boolean isNotEmpty()

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

last

public final @NonNulllast()

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

last

public final @NonNulllast(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

lastIndexOf

public final int lastIndexOf(@NonNull T element)

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

lastOrNull

public final T lastOrNull()

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

lastOrNull

public final T lastOrNull(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

map

public final @NonNull R[] <R extends Object> map(@NonNull Function1<@NonNull T, @NonNull R> transform)

Returns an Array of results of transforming each element in the MutableVector. The Array will be the same size as this.

mapIndexed

public final @NonNull R[] <R extends Object> mapIndexed(
    @NonNull Function2<@NonNull Integer, @NonNull T, @NonNull R> transform
)

Returns an Array of results of transforming each element in the MutableVector. The Array will be the same size as this.

mapIndexedNotNull

public final @NonNull MutableVector<@NonNull R> <R extends Object> mapIndexedNotNull(
    @NonNull Function2<@NonNull Integer, @NonNull T, R> transform
)

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

mapNotNull

public final @NonNull MutableVector<@NonNull R> <R extends Object> mapNotNull(@NonNull Function1<@NonNull T, R> transform)

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

minusAssign

public final void minusAssign(@NonNull T element)

remove from the MutableVector

plusAssign

public final void plusAssign(@NonNull T element)

add to the MutableVector.

remove

public final boolean remove(@NonNull T element)

Removes element from the MutableVector. If element was in the MutableVector and was removed, true will be returned, or false will be returned if the element was not found.

removeAll

public final boolean removeAll(@NonNull Collection<@NonNull T> elements)

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

removeAll

public final boolean removeAll(@NonNull List<@NonNull T> elements)

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

removeAll

public final boolean removeAll(@NonNull MutableVector<@NonNull T> elements)

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

removeAt

public final @NonNullremoveAt(int index)

Removes the element at the given index and returns it.

removeRange

public final void removeRange(int start, int end)

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

retainAll

public final boolean retainAll(@NonNull Collection<@NonNull T> elements)

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

reversedAny

public final boolean reversedAny(@NonNull Function1<@NonNull T, @NonNull Boolean> predicate)

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

set

public final @NonNullset(int index, @NonNull T element)

Sets the value at index to element.

sortWith

public final void sortWith(@NonNull Comparator<@NonNull T> comparator)

Sorts the MutableVector using comparator to order the items.

sumBy

public final int sumBy(@NonNull Function1<@NonNull T, @NonNull Integer> selector)

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