Hanbit the Developer
Kotlin Documentation | Constructing collections 본문
Category: Standard library - Collections
문서 링크: https://kotlinlang.org/docs/constructing-collections.html
Create with collection builder functions
val map = buildMap { // this is MutableMap<String, Int>, types of key and value are inferred from the `put()` calls below
put("a", 1)
put("b", 0)
put("c", 4)
}
println(map) // {a=1, b=0, c=4}
Initializer functions for lists
val doubled = List(3, { it * 2 }) // or MutableList if you want to change its content later
println(doubled)
→ [0, 2, 4]
Copy
toList(), toMutableList(), toSet()를 통해 컬렉션을 deepcopy 할 수 있다.
'Kotlin' 카테고리의 다른 글
Kotlin Documentation | Ranges and progressions (0) | 2023.05.24 |
---|---|
Kotlin Documentation | Iterators (0) | 2023.05.24 |
Kotlin Documentation | Collections overview (0) | 2023.05.24 |
Kotlin Documentation | Operator overloading (0) | 2023.05.23 |
Kotlin Documentation | Inline functions (0) | 2023.05.23 |