lastIndex
val ByteArray.lastIndex: Intval ShortArray.lastIndex: Intval IntArray.lastIndex: Intval LongArray.lastIndex: Intval FloatArray.lastIndex: Intval DoubleArray.lastIndex: Intval BooleanArray.lastIndex: Intval CharArray.lastIndex: Int@ExperimentalUnsignedTypes inline val UIntArray.lastIndex: Int@ExperimentalUnsignedTypes inline val ULongArray.lastIndex: Int@ExperimentalUnsignedTypes inline val UByteArray.lastIndex: Int@ExperimentalUnsignedTypes inline val UShortArray.lastIndex: IntReturns the last valid index for the array.
val <T> List<T>.lastIndex: IntReturns the index of the last item in the list or -1 if the list is empty.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
println(emptyList<Any>().lastIndex) // -1
val list = listOf("a", "x", "y")
println(list.lastIndex) // 2
println(list[list.lastIndex]) // y
//sampleEnd
}