germx.blogg.se

Kotlin find in list
Kotlin find in list





kotlin find in list

In case of List, it's more idiomatic to use indexed access operator ( get() or ). The first element has the position 0, and the last one is (size - 1).ĮlementAt() is useful for collections that do not provide indexed access, or are not statically known to provide one. Call it with the integer number as an argument, and you'll receive the collection element at the given position. Retrieve by positionįor retrieving an element at a specific position, there is the function elementAt().

kotlin find in list

However, such results are unpredictable to the caller unless they know the specific implementation of Set used. In such cases, the elements are still ordered somehow, so the functions that rely on the element positions still return their results. The order of a set of elements can also be unknown. These can be the order of insertion (in LinkedHashSet), natural sorting order (in SortedSet), or another order. However, the Kotlin Set stores elements in certain orders. In turn, set is not an ordered collection by definition. For more details, see List-specific operations.

abstract fun listIterator() MutableListIterator Returns a list iterator over the elements in this list (in proper sequence), starting at the specified index abstract fun listIterator(index: Int): MutableListIterator Common JVM JS Native 1.

In addition to functions described on this page, lists offer a wider set of ways to retrieve and search for elements by indices. listIterator Returns a list iterator over the elements in this list (in proper sequence). Hence, every element of a list has its position that you can use for referring. Functions described on this page apply to both lists and sets.Īs the definition of list says, a list is an ordered collection. Kotlin collections provide a set of functions for retrieving single elements from collections.







Kotlin find in list