Hanbit the Developer
Kotlin Documentation | Set-specific operations 본문
Category: Standard library - Collections
문서 링크: https://kotlinlang.org/docs/set-operations.html
- union(), intersect(), subtract(): infix fun
val numbers = setOf("one", "two", "three")
println(numbers union setOf("four", "five"))
println(setOf("four", "five") union numbers)
println(numbers intersect setOf("two", "one"))
println(numbers subtract setOf("three", "four"))
println(numbers subtract setOf("four", "three")) // same output
println(numbers subtract setOf("four", "three")) // same output
[one, two, three, four, five]
[four, five, one, two, three]
[one, two]
[one, two]
[one, two]
위 함수들을 list에도 동일하게 사용할 수 있으나 Set을 반환한다.
'Kotlin' 카테고리의 다른 글
Kotlin Documentation | Scope functions (0) | 2023.05.24 |
---|---|
Kotlin Documentation | Map-specific operations (0) | 2023.05.24 |
Kotlin Documentation | List-specific operations (0) | 2023.05.24 |
Kotlin Documentation | Write operations (0) | 2023.05.24 |
Kotlin Documentation | Aggregate operations (0) | 2023.05.24 |