Moosphan / Android-Daily-Interview

:pushpin:每工作日更新一道 Android 面试题,小聚成河,大聚成江,共勉之~

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Moosphan opened this issue · 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")
}

`