October 2018
Intermediate to advanced
370 pages
9h 15m
English
There are a number of ways to access list elements, most of which are similar to the ways in which we access arrays. We can access each element of the list by using either the [ ] subscript operator or the get function:
val listOfString = listOf<String>("One", "Two", "Three", "Four", "Three", "Five")var element = listOfString[0]element = listOfString.get(1)
listOfString[0] returns One and listOfString.get(1) returns Two.
We can get the index of a specific value in the list using the indexOf function. The following function, for example, will return 2:
var index = listOfString.indexOf("Three")
If the list contains more elements of the same type, the indexOf function will return the index of the first element. The lastIndexOf function, ...
Read now
Unlock full access