Notice
Recent Posts
Recent Comments
Link
목록Kotlin (1)
정답보다 해답을
[Kotlin] map와 forEach의 차이점
코틀린 함수 중 forEach와 map에 대해 알아봅시다. forEach과 map 함수는 모두 컬렉션의 각 요소에 대해 동작을 수행하지만, 그 동작의 결과에 차이가 있습니다. Map fun main() { val people = listOf(Person("Alice", 29), Person("Bob", 31)) println(people.map {it.name}) } data class Person(val name: String, val age: Int) 위와 같은 코드가 있을 때 어떤 결과가 나올까요?? 예상했듯, Person 객체 안에 name을 잘 출력하고 있네요! forEach fun main() { val people = listOf(Person("Alice", 29), Person("Bob",..
Kotlin
2024. 4. 13. 15:05