美文网首页
Kotlin之数组遍历

Kotlin之数组遍历

作者: xu_pan | 来源:发表于2020-09-17 19:28 被阅读0次
   val array: Array<String> = Array(5) { (it * it).toString() }

    for (index in array.indices) {
        println("$index->${array[index]}")
    }
    println("=====================");

    for (item in array) {
        println(item)
    }
    println("=====================");

    array.forEach { println(it) }
    println("=====================");

    array.forEachIndexed { index, item -> println("$index->$item") }

输出

0->0
1->1
2->4
3->9
4->16
=====================
0
1
4
9
16
=====================
0
1
4
9
16
=====================
0->0
1->1
2->4
3->9
4->16

相关文章

网友评论

      本文标题:Kotlin之数组遍历

      本文链接:https://www.haomeiwen.com/subject/sorryktx.html