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
val ShortArray.lastIndex: Int
val IntArray.lastIndex: Int
val LongArray.lastIndex: Int
val FloatArray.lastIndex: Int
val DoubleArray.lastIndex: Int
val BooleanArray.lastIndex: Int
val CharArray.lastIndex: Int

Returns the last valid index for the array.

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/last-index.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部