kotlin forEachIndexed arrayListOf<String>

kotlin forEachIndexed arrayListOf

 

import java.lang.StringBuilder

fun main(args: Array) {
    var bundle = "fly"
    var str = StringBuilder()
    var list = arrayListOf()
    bundle.forEachIndexed { index, s ->
        when (index) {
            0 -> str.append(s)
            1 -> str.append(s)
            else -> {

            }
        }

        list.add(s.toString())
    }

    println(str)
    println(list)
}

 

fl
[f, l, y]

 

 

Python for循环中的zip_python zip函数用于for循环_zhangphil的博客-CSDN博客s = ["1", "2", "3", "4", "5"]t = ["a", "b", "c", "d", "e"]for x, y in zip(s, t): print(x+"-"+y)print("######")u = {"1", "2", "3", "4", "5"}v = {"a", "b", "c", "d", "e"}for x, y in zi...https://blog.csdn.net/zhangphil/article/details/90053306

 

你可能感兴趣的:(kotlin,kotlin)