Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- List
- crawler
- 플러터
- Collection
- animation
- pushnamed
- 코틀린
- 다트
- set
- text
- 클래스
- function
- 함수
- textstyle
- texttheme
- variable
- Flutter
- DART
- 크롤러
- map
- Android
- package
- 파이썬
- ML
- 콜렉션
- python
- 웹크롤러
- Class
- kotlin
- import
Archives
- Today
- Total
조용한 담장
코틀린(Kotlin) Collections : Set Specific Operations 본문
코틀린의 collection 의 Set Specific Operations 에 대해 살펴보자.
원문 https://kotlinlang.org/docs/reference/set-operations.html 을 보며 정리.
두개의 collection 을 합칠때는 union() 함수를 사용한다. infix a union b 로도 사용한다.
intersect() 는 두 collection 에 모두 있는 element 를 찾는다. infix a intersect b
subtract() 는 한쪽 collection 에만 있는 element 를 찾는다. infix a subtract b
val numbers = setOf("one", "two", "three")
println(numbers union setOf("four", "five")) // [one, two, three, four, five]
println(setOf("four", "five") union numbers) // [four, five, one, two, three]
println(numbers intersect setOf("two", "one")) // [one, two]
println(numbers subtract setOf("three", "four")) // [one, two]
println(numbers subtract setOf("four", "three")) // [one, two]
set operation 은 List 도 지원하지만 set operation 의 결과는 여전히 Set 이기 때문에 중복되는 element 는 삭제된다.
'kotlin' 카테고리의 다른 글
The ins and outs of Kotlin (0) | 2020.07.28 |
---|---|
코틀린(Kotlin) Collections : Map Specific Operations (0) | 2020.05.08 |
코틀린(Kotlin) Collections : List Specific Operations (0) | 2020.05.07 |
코틀린(Kotlin) Collections : Write Operations (0) | 2020.04.14 |
코틀린(Kotlin) Collections : Aggregate Operations (0) | 2020.04.08 |
Comments