Skip to content
Kotlin

kotlin.collections.List API Reference

Kotlin's List<T> — an immutable ordered collection; MutableList<T> adds in-place mutation.

By EZ4Code Team

List<T>

A generic ordered collection of elements. List is read-only; MutableList supports modification.

List.size: Int

Returns the number of elements in this collection.

Returns: Int

MutableList.add(element: E): Boolean

Adds the specified element to the end of this list. Returns true.

Returns: Boolean

MutableList.remove(element: E): Boolean

Removes the first occurrence of the specified element. Returns true if removed.

Returns: Boolean

List.contains(element: E): Boolean

Returns true if element is found in the collection.

Returns: Boolean

List.map { it -> R }: List<R>

Returns a list containing the results of applying transform to each element.

Returns: List<R>

List.filter { it -> Boolean }: List<E>

Returns a list containing only elements matching the given predicate.

Returns: List<E>

List.sorted(): List<E>

Returns a new list with all elements sorted ascending according to their natural order.

Returns: List<E>

List.forEach { it -> Unit }

Performs the given action on each element in order.

Returns: Unit

More Kotlin API References