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

SnapshotStateList

public final class SnapshotStateList<T extends Object> implements MutableList, StateObject


An implementation of MutableList that can be observed and snapshot. This is the result type created by androidx.compose.runtime.mutableStateListOf.

This class closely implements the same semantics as ArrayList.

See also
mutableStateListOf

Summary

Public constructors

<T extends Object> SnapshotStateList()

Public methods

boolean
add(@NonNull T element)
void
add(int index, @NonNull T element)
boolean
boolean
addAll(int index, @NonNull Collection<@NonNull T> elements)
void
boolean
contains(@NonNull T element)
boolean
@NonNull T
get(int index)
@NonNull StateRecord

The first state record in a linked list of state records.

int
int
indexOf(@NonNull T element)
boolean
@NonNull Iterator<@NonNull T>
int
lastIndexOf(@NonNull T element)
@NonNull ListIterator<@NonNull T>
@NonNull ListIterator<@NonNull T>
listIterator(int index)
void

Add a new state record to the beginning of a list.

boolean
remove(@NonNull T element)
boolean
@NonNull T
removeAt(int index)
final void
removeRange(int fromIndex, int toIndex)
boolean
@NonNull T
set(int index, @NonNull T element)
@NonNull List<@NonNull T>
subList(int fromIndex, int toIndex)
final @NonNull List<@NonNull T>

Return a list containing all the elements of this list.

Inherited methods

From androidx.compose.runtime.snapshots.StateObject
StateRecord
mergeRecords(
    @NonNull StateRecord previous,
    @NonNull StateRecord current,
    @NonNull StateRecord applied
)

Produce a merged state based on the conflicting state changes.

Public constructors

SnapshotStateList

public <T extends Object> SnapshotStateList()

Public methods

add

public boolean add(@NonNull T element)

add

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

addAll

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

addAll

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

clear

public void clear()

contains

public boolean contains(@NonNull T element)

containsAll

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

get

public @NonNullget(int index)

getFirstStateRecord

public @NonNull StateRecord getFirstStateRecord()

The first state record in a linked list of state records.

getSize

public int getSize()

indexOf

public int indexOf(@NonNull T element)

isEmpty

public boolean isEmpty()

iterator

public @NonNull Iterator<@NonNull T> iterator()

lastIndexOf

public int lastIndexOf(@NonNull T element)

listIterator

public @NonNull ListIterator<@NonNull T> listIterator()

listIterator

public @NonNull ListIterator<@NonNull T> listIterator(int index)

prependStateRecord

public void prependStateRecord(@NonNull StateRecord value)

Add a new state record to the beginning of a list. After this call firstStateRecord should be value.

remove

public boolean remove(@NonNull T element)

removeAll

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

removeAt

public @NonNullremoveAt(int index)

removeRange

public final void removeRange(int fromIndex, int toIndex)

retainAll

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

set

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

subList

public @NonNull List<@NonNull T> subList(int fromIndex, int toIndex)

toList

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

Return a list containing all the elements of this list.

The list returned is immutable and returned will not change even if the content of the list is changed in the same snapshot. It also will be the same instance until the content is changed. It is not, however, guaranteed to be the same instance for the same list as adding and removing the same item from the this list might produce a different instance with the same content.

This operation is O(1) and does not involve a physically copying the list. It instead returns the underlying immutable list used internally to store the content of the list.

It is recommended to use toList when using returning the value of this list from androidx.compose.runtime.snapshotFlow.