코틀린/[Elements] 요소 작업8 [Kotlin][Collection] forEach / forEachIndexed 각 요소에 대해 지정된 작업을 수행합니다.public inline fun Iterator.forEach(operation: (T) -> Unit): Unit { for (element in this) operation(element)}val list = listOf(1, 2, 3, 4)list.forEach { num -> print(num) } // 1234 각 요소에 대해 지정된 작업을 수행하여 요소에 순차적 인덱스를 제공합니다.public inline fun Iterable.forEachIndexed(action: (index: Int, T) -> Unit): Unit { var index = 0 for (item in this) action(checkIndexOverflow(i.. 2024. 8. 9. 이전 1 2 다음