Moosphan/Android-Daily-Interview

2020-01-10:Kotlin中集合遍历有哪几种方式?

Moosphan opened this issue · 3 comments

2020-01-10:Kotlin中集合遍历有哪几种方式?

for,foreach,while,do while,递归,还有集合的高阶方法

`var mutableList: MutableList = mutableListOf(1, 2, 3, 4)
// 方式1
mutableList.forEach {
println("Mutable List Elements:$it")
}

//方式和2
for (value in mutableList) {
print("value:$value")
}
//方式3
for ((index, str) in mutableList.withIndex()) {
LogUtils.d("index$index value:$str")
}

`