지정된 컬렉션의 고유한 요소만 포함하는 목록을 반환합니다. 주어진 컬렉션의 동일한 요소 중에서 첫 번째 요소만 결과 목록에 표시됩니다. 결과 목록의 요소는 소스 컬렉션의 순서와 동일합니다.
public fun <T> Iterable<T>.distinct(): List<T> {
return this.toMutableSet().toList()
}
val list = listOf('a', 'A', 'b', 'B', 'A', 'a')
println(list.distinct()) // [a, A, b, B]
println(list.distinctBy { it.uppercaseChar() }) // [a, b]
distinct - Kotlin Programming Language
kotlinlang.org
'코틀린 > [Filtering] 필터 작업' 카테고리의 다른 글
[Kotlin][Collection] removeFirst / removeLast / removeAt (0) | 2024.09.06 |
---|---|
[Kotlin][Number] coerceAtMost (0) | 2024.09.02 |
[Kotlin][Collection] dropWhile / dropLastWhile (0) | 2024.08.28 |