小编Roh*_*mar的帖子

Kotlin的.indices是什么意思?

我想知道.indices的工作原理,这两个for循环之间的主要区别是什么。

for (arg in args)
    println(arg)
Run Code Online (Sandbox Code Playgroud)

要么

for (i in args.indices)
    println(args[i])
Run Code Online (Sandbox Code Playgroud)

withIndex()函数的用途是什么

for ((index, value) in array.withIndex()) {
    println("the element at $index is $value")
}
Run Code Online (Sandbox Code Playgroud)

kotlin

6
推荐指数
1
解决办法
1495
查看次数

在Kotlin宣布空集合

我怎样才能申报一个空的收集mapOf,listOfsetOf科特林

我在下面声明了变量:

val occupations = mapOf(Pair("Malcolm", "Captain"), Pair("Kaylee", "Mechanic"))
val shoppingList = listOf("catfish", "water", "tulips", "blue paint")
val favoriteGenres = setOf("Rock", "Classical", "Hip hop") 
Run Code Online (Sandbox Code Playgroud)

我想检查这些集合是否为空.

kotlin

6
推荐指数
2
解决办法
4982
查看次数

标签 统计

kotlin ×2