kotlin.collections.lastIndex

lastIndex

val <T> List<T>.lastIndex: Int

Returns the index of the last item in the list or -1 if the list is empty.

import kotlin.test.*
import java.util.*

fun main(args: Array<String>) {
//sampleStart
println(emptyList<Any>().lastIndex) // -1
println(listOf("a", "x", "y").lastIndex) // 2
//sampleEnd
}
val <T> Array<out T>.lastIndex: Int
val ByteArray.lastIndex: Int
登录查看完整内容