distinct

Common
JVM
JS
Native
1.0
fun <T> Array<out T>.distinct(): List<T>
(source)

Returns a list containing only distinct elements from the given array.

Among equal elements of the given array, only the first one will be present in the resulting list. The elements in the resulting list are in the same order as they were in the source array.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val list = listOf('a', 'A', 'b', 'B', 'A', 'a')
println(list.distinct()) // [a, A, b, B]
println(list.distinctBy { it.uppercaseChar() }) // [a, b]
//sampleEnd
}
Common
JVM
JS
Native
1.0
fun ByteArray.distinct(): List<Byte>
(source)
fun ShortArray.distinct(): List<Short>
(source)
fun IntArray.distinct(): List<Int>
(source)
fun LongArray.distinct(): List<Long>
(source)
fun FloatArray.distinct(): List<Float>
(source)
fun DoubleArray.distinct(): List<Double>
(source)
fun BooleanArray.distinct(): List<Boolean>
(source)
fun CharArray.distinct(): List<Char>
(source)

Returns a list containing only distinct elements from the given array.

The elements in the resulting list are in the same order as they were in the source array.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val list = listOf('a', 'A', 'b', 'B', 'A', 'a')
println(list.distinct()) // [a, A, b, B]
println(list.distinctBy { it.uppercaseChar() }) // [a, b]
//sampleEnd
}
Common
JVM
JS
Native
1.0
fun <T> Iterable<T>.distinct(): List<T>
(source)

Returns a list containing only distinct elements from the given collection.

Among equal elements of the given collection, only the first one will be present in the resulting list. The elements in the resulting list are in the same order as they were in the source collection.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val list = listOf('a', 'A', 'b', 'B', 'A', 'a')
println(list.distinct()) // [a, A, b, B]
println(list.distinctBy { it.uppercaseChar() }) // [a, b]
//sampleEnd
}