sorted Map Of
fun <K : Comparable<K>, V> sortedMapOf(vararg pairs: Pair<K, V>): SortedMap<K, V>
Content copied to clipboard
Returns a new SortedMap with the specified contents, given as a list of pairs where the first value is the key and the second is the value.
The resulting SortedMap determines the equality and order of keys according to their natural sorting order.
Samples
import samples.*
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
val map = sortedMapOf(Pair("c", 3), Pair("b", 2), Pair("d", 1))
assertPrints(map.keys, "[b, c, d]")
assertPrints(map.values, "[2, 3, 1]")
//sampleEnd
}
fun <K, V> sortedMapOf(comparator: Comparator<in K>, vararg pairs: Pair<K, V>): SortedMap<K, V>
Content copied to clipboard
Returns a new SortedMap with the specified contents, given as a list of pairs where the first value is the key and the second is the value.
The resulting SortedMap determines the equality and order of keys according to the sorting order provided by the given comparator.
Since Kotlin
1.4
Samples
import samples.*
import kotlin.test.*
import java.util.*
fun main() {
//sampleStart
val map = sortedMapOf(compareBy<String> { it.length }.thenBy { it }, Pair("abc", 1), Pair("c", 3), Pair("bd", 4), Pair("bc", 2))
assertPrints(map.keys, "[c, bc, bd, abc]")
assertPrints(map.values, "[3, 2, 4, 1]")
//sampleEnd
}