last Index
Returns the last valid index for the array.
Returns the last valid index for the array.
Since Kotlin
1.3
Returns the index of the last item in the list or -1 if the list is empty.
Samples
import samples.*
import kotlin.test.*
fun main() {
//sampleStart
assertPrints(emptyList<Any>().lastIndex, "-1")
val list = listOf("a", "x", "y")
assertPrints(list.lastIndex, "2")
assertPrints(list[list.lastIndex], "y")
//sampleEnd
}