在 Kotlin 中,可以使用 indexOf 方法来获取 ArrayList 中某个元素的下标。例如:

val list = arrayListOf("A", "B", "C", "D")
val index = list.indexOf("C")
println("元素 C 的下标为:$index")

输出结果为:

元素 C 的下标为:2

如果 ArrayList 中不存在该元素,则 indexOf 方法会返回 -1。

kotlin 获取Arraylist某个元素的下标

原文地址: https://www.cveoy.top/t/topic/ht5A 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录