코딩일기/Kotlin(2)
-
Kotlin - zip, joinToString
zip val listA = listOf("a", "b", "c") val listB = listOf(1, 2, 3, 4) println(listA zip listB) // [(a, 1), (b, 2), (c, 3)] val listA = listOf("a", "b", "c") val listB = listOf(1, 2, 3, 4) val result = listA.zip(listB) { a, b -> "$a$b" } println(result) // [a1, b2, c3] joinToString() val numbers = listOf(1, 2, 3, 4, 5, 6) println(numbers.joinToString()) // 1, 2, 3, 4, 5, 6 println(numbers.joinToSt..
2023.06.13 -
Kotlin - repeat
fun main(args: Array) { // greets three times repeat(3) { print("Hello ") } println() // greets with an index repeat(3) { index -> println("Hello with index $index") } println("a".repeat(3)) repeat(0) { error("We should not get here!") } } 결과 Hello Hello Hello Hello with index 0 Hello with index 1 Hello with index 2 aaa https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/repeat.html 위 링크에서 이것저것 ..
2023.06.13