gpt4 book ai didi

arrays - Kotlin forEach 订单

转载 作者:行者123 更新时间:2023-12-04 16:10:17 31 4
gpt4 key购买 nike

Kotlin forEach 是按数组的实际顺序遍历数组还是有时可能按其他顺序遍历数组?我的意思是这是否总是打印 1,2,3,...9 或者它可能会打印类似 1,5,3,4,...

val numbers: Array<Int> = array(1,2,3,4,5,6,7,8,9)
numbers.forEach({(number: Int) ->
Log.d(tag,number)
})

Kotlin forEach reference

最佳答案

forEach从第一个元素到最后一个元素按顺序迭代;源代码:
Collections.kt

/**
* Performs the given [action] on each element.
*/
@kotlin.internal.HidesMembers
public inline fun <T> Iterable<T>.forEach(action: (T) -> Unit): Unit {
for (element in this) action(element)
}

关于arrays - Kotlin forEach 订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47842940/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com