MutableIntList



MutableIntList is a MutableList-like collection for Int values. It allows storing and retrieving the elements without boxing. Immutable access is available through its base class IntList, which has a List-like interface.

This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the list (insertion or removal for instance), the calling code must provide the appropriate synchronization. It is also not safe to mutate during reentrancy -- in the middle of a forEach, for example. However, concurrent reads are safe.

Summary

Public constructors

MutableIntList(initialCapacity: Int)

Creates a MutableIntList with a capacity of initialCapacity.

Cmn

Public functions

Boolean
add(element: Int)

Adds element to the MutableIntList and returns true.

Cmn
Unit
add(index: @IntRange(from = 0) Int, element: Int)

Adds element to the MutableIntList at the given index, shifting over any elements at index and after, if any.

Cmn
Boolean
addAll(elements: IntArray)

Adds all elements to the end of the MutableIntList and returns true if the MutableIntList was changed or false if elements was empty.

Cmn
Boolean
addAll(elements: IntList)

Adds all elements to the end of the MutableIntList and returns true if the MutableIntList was changed or false if elements was empty.

Cmn
Boolean
addAll(index: @IntRange(from = 0) Int, elements: IntArray)

Adds all elements to the MutableIntList at the given index, shifting over any elements at index and after, if any.

Cmn
Boolean
addAll(index: @IntRange(from = 0) Int, elements: IntList)

Adds all elements to the MutableIntList at the given index, shifting over any elements at index and after, if any.

Cmn
Unit

Removes all elements in the MutableIntList.

Cmn
Unit
ensureCapacity(capacity: Int)

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

Cmn
inline operator Unit
minusAssign(element: Int)

remove from the MutableIntList

Cmn
operator Unit
minusAssign(elements: IntArray)

Removes all elements from the MutableIntList.

Cmn
operator Unit
minusAssign(elements: IntList)

Removes all elements from the MutableIntList.

Cmn
inline operator Unit
plusAssign(element: Int)

add to the MutableIntList.

Cmn
operator Unit
plusAssign(elements: IntArray)

Adds all elements to the end of the MutableIntList.

Cmn
operator Unit
plusAssign(elements: IntList)

Adds all elements to the end of the MutableIntList.

Cmn
Boolean
remove(element: Int)

Removes element from the MutableIntList.

Cmn
Boolean
removeAll(elements: IntArray)

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

Cmn
Boolean
removeAll(elements: IntList)

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

Cmn
Int
removeAt(index: @IntRange(from = 0) Int)

Removes the element at the given index and returns it.

Cmn
Unit
removeRange(start: @IntRange(from = 0) Int, end: @IntRange(from = 0) Int)

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

Cmn
Boolean
retainAll(elements: IntArray)

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

Cmn
Boolean
retainAll(elements: IntList)

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

Cmn
operator Int
set(index: @IntRange(from = 0) Int, element: Int)

Sets the value at index to element.

Cmn
Unit

Sorts the MutableIntList elements in ascending order.

Cmn
Unit

Sorts the MutableIntList elements in descending order.

Cmn
Unit
trim(minCapacity: Int)

Reduces the internal storage.

Cmn

Public properties

Int

Returns the total number of elements that can be held before the MutableIntList must grow.

Cmn

Inherited functions

From androidx.collection.IntList
Boolean
any()

Returns true if there's at least one element in the collection.

Cmn
inline Boolean
any(predicate: (element: Int) -> Boolean)

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

Cmn
operator Boolean
contains(element: Int)

Returns true if the IntList contains element or false otherwise.

Cmn
Boolean
containsAll(elements: IntList)

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

Cmn
Int

Returns the number of elements in this list.

Cmn
inline Int
count(predicate: (element: Int) -> Boolean)

Counts the number of elements matching predicate.

Cmn
Int
elementAt(index: @IntRange(from = 0) Int)

Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.

Cmn
inline Int
elementAtOrElse(
    index: @IntRange(from = 0) Int,
    defaultValue: (index: Int) -> Int
)

Returns the element at the given index or defaultValue if index is out of bounds of the collection.

Cmn
open operator Boolean
equals(other: Any?)

Returns true if other is a IntList and the contents of this and other are the same.

Cmn
Int

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

Cmn
inline Int
first(predicate: (element: Int) -> Boolean)

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

Cmn
inline R
<R : Any?> fold(initial: R, operation: (acc, element: Int) -> R)

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

Cmn
inline R
<R : Any?> foldIndexed(initial: R, operation: (index: Int, acc, element: Int) -> R)

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

Cmn
inline R
<R : Any?> foldRight(initial: R, operation: (element: Int, acc) -> R)

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

Cmn
inline R
<R : Any?> foldRightIndexed(
    initial: R,
    operation: (index: Int, element: Int, acc) -> R
)

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

Cmn
inline Unit
forEach(block: (element: Int) -> Unit)

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

Cmn
inline Unit
forEachIndexed(block: (index: Int, element: Int) -> Unit)

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

Cmn
inline Unit
forEachReversed(block: (element: Int) -> Unit)

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

Cmn
inline Unit
forEachReversedIndexed(block: (index: Int, element: Int) -> Unit)

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

Cmn
operator Int
get(index: @IntRange(from = 0) Int)

Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.

Cmn
open Int

Returns a hash code based on the contents of the IntList.

Cmn
Int
indexOf(element: Int)

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

Cmn
inline Int
indexOfFirst(predicate: (element: Int) -> Boolean)

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

Cmn
inline Int
indexOfLast(predicate: (element: Int) -> Boolean)

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

Cmn
Boolean

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

Cmn
Boolean

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

Cmn
String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence
)

Creates a String from the elements separated by separator and using prefix before and postfix after, if supplied.

Cmn
inline String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence,
    crossinline transform: (Int) -> CharSequence
)

Creates a String from the elements separated by separator and using prefix before and postfix after, if supplied.

Cmn
Int

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

Cmn
inline Int
last(predicate: (element: Int) -> Boolean)

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

Cmn
Int
lastIndexOf(element: Int)

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

Cmn
Boolean

Returns true if the collection has no elements in it.

Cmn
inline Boolean
reversedAny(predicate: (element: Int) -> Boolean)

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

Cmn
open String

Returns a String representation of the list, surrounded by "[]" and each element separated by ", ".

Cmn

Inherited properties

From androidx.collection.IntList
IntRange

Returns an IntRange of the valid indices for this IntList.

Cmn
Int

Returns the last valid index in the IntList.

Cmn
Int

The number of elements in the IntList.

Cmn

Public constructors

MutableIntList

MutableIntList(initialCapacity: Int = 16)

Creates a MutableIntList with a capacity of initialCapacity.

Public functions

add

fun add(element: Int): Boolean

Adds element to the MutableIntList and returns true.

add

fun add(index: @IntRange(from = 0) Int, element: Int): Unit

Adds element to the MutableIntList at the given index, shifting over any elements at index and after, if any.

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and size, inclusive

addAll

fun addAll(elements: IntArray): Boolean

Adds all elements to the end of the MutableIntList and returns true if the MutableIntList was changed or false if elements was empty.

addAll

fun addAll(elements: IntList): Boolean

Adds all elements to the end of the MutableIntList and returns true if the MutableIntList was changed or false if elements was empty.

addAll

fun addAll(index: @IntRange(from = 0) Int, elements: IntArray): Boolean

Adds all elements to the MutableIntList at the given index, shifting over any elements at index and after, if any.

Returns
Boolean

true if the MutableIntList was changed or false if elements was empty

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and size, inclusive.

addAll

fun addAll(index: @IntRange(from = 0) Int, elements: IntList): Boolean

Adds all elements to the MutableIntList at the given index, shifting over any elements at index and after, if any.

Returns
Boolean

true if the MutableIntList was changed or false if elements was empty

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and size, inclusive

clear

fun clear(): Unit

Removes all elements in the MutableIntList. The storage isn't released.

See also
trim

ensureCapacity

fun ensureCapacity(capacity: Int): Unit

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

See also
trim

minusAssign

inline operator fun minusAssign(element: Int): Unit

remove from the MutableIntList

minusAssign

operator fun minusAssign(elements: IntArray): Unit

Removes all elements from the MutableIntList.

minusAssign

operator fun minusAssign(elements: IntList): Unit

Removes all elements from the MutableIntList.

plusAssign

inline operator fun plusAssign(element: Int): Unit

add to the MutableIntList.

plusAssign

operator fun plusAssign(elements: IntArray): Unit

Adds all elements to the end of the MutableIntList.

plusAssign

operator fun plusAssign(elements: IntList): Unit

Adds all elements to the end of the MutableIntList.

remove

fun remove(element: Int): Boolean

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

removeAll

fun removeAll(elements: IntArray): Boolean

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

removeAll

fun removeAll(elements: IntList): Boolean

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

removeAt

fun removeAt(index: @IntRange(from = 0) Int): Int

Removes the element at the given index and returns it.

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and lastIndex, inclusive

removeRange

fun removeRange(start: @IntRange(from = 0) Int, end: @IntRange(from = 0) Int): Unit

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

Throws
kotlin.IndexOutOfBoundsException

if start or end isn't between 0 and size, inclusive

kotlin.IllegalArgumentException

if start is greater than end

retainAll

fun retainAll(elements: IntArray): Boolean

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

Returns
Boolean

true if the MutableIntList has changed.

retainAll

fun retainAll(elements: IntList): Boolean

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

Returns
Boolean

true if the MutableIntList has changed.

set

operator fun set(index: @IntRange(from = 0) Int, element: Int): Int

Sets the value at index to element.

Returns
Int

the previous value set at index

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and lastIndex, inclusive

sort

fun sort(): Unit

Sorts the MutableIntList elements in ascending order.

sortDescending

fun sortDescending(): Unit

Sorts the MutableIntList elements in descending order.

trim

fun trim(minCapacity: Int = _size): Unit

Reduces the internal storage. If capacity is greater than minCapacity and size, the internal storage is reduced to the maximum of size and minCapacity.

See also
ensureCapacity

Public properties

capacity

val capacityInt

Returns the total number of elements that can be held before the MutableIntList must grow.

See also
ensureCapacity