Hanbit the Developer
Kotlin Documentation | Write operations 본문
Category: Standard library - Collections
문서 링크: https://kotlinlang.org/docs/collection-write.html
Adding elements
- add(), addAll()
- +=
val numbers = mutableListOf("one", "two")
numbers += "three"
println(numbers)
numbers += listOf("four", "five")
println(numbers)
Removing elements
- remove(), removeAll()
- retainAll(): removeAll()의 반대. 주어진 컬렉션만을 남긴다.
- clear()
- -=
val numbers = mutableListOf("one", "two", "three", "three", "four")
numbers -= "three"
println(numbers)
numbers -= listOf("four", "five")
//numbers -= listOf("four") // does the same as above
println(numbers)
[one, two, three, four]
[one, two, three]
'Kotlin' 카테고리의 다른 글
Kotlin Documentation | Set-specific operations (0) | 2023.05.24 |
---|---|
Kotlin Documentation | List-specific operations (0) | 2023.05.24 |
Kotlin Documentation | Aggregate operations (0) | 2023.05.24 |
Kotlin Documentation | Ordering (0) | 2023.05.24 |
Kotlin Documentation | Retrieve single elements (0) | 2023.05.24 |