indices所在位置是kotlin.collections.indices,其相关用法介绍如下。

用法一

val <T> Array<out T>.indices: IntRange
val ByteArray.indices: IntRange
val ShortArray.indices: IntRange
val IntArray.indices: IntRange
val LongArray.indices: IntRange
val FloatArray.indices: IntRange
val DoubleArray.indices: IntRange
val BooleanArray.indices: IntRange
val CharArray.indices: IntRange
@ExperimentalUnsignedTypes inline val UIntArray.indices: IntRange
@ExperimentalUnsignedTypes inline val ULongArray.indices: IntRange
@ExperimentalUnsignedTypes inline val UByteArray.indices: IntRange
@ExperimentalUnsignedTypes inline val UShortArray.indices: IntRange

返回数组的有效索引范围。

用法二

val Collection<*>.indices: IntRange

返回此集合的有效索引的 IntRange

例子:

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val empty = emptyList<Any>()
println("empty.indices.isEmpty() is ${empty.indices.isEmpty()}") // true
val collection = listOf('a', 'b', 'c')
println(collection.indices) // 0..2
//sampleEnd
}

输出:

empty.indices.isEmpty() is true
0..2