W3cubDocs

/Kotlin

linkedMapOf

inline fun <K, V> linkedMapOf(): LinkedHashMap<K, V>

Platform and version requirements: Kotlin 1.1

Returns an empty new LinkedHashMap.

fun <K, V> linkedMapOf(
    vararg pairs: Pair<K, V>
): LinkedHashMap<K, V>

Returns a new LinkedHashMap with the specified contents, given as a list of pairs where the first component is the key and the second is the value. If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs. Entries of the map are iterated in the order they were specified.

import kotlin.test.*
import java.util.*
import kotlin.comparisons.*

fun main(args: Array<String>) {
//sampleStart
val map: LinkedHashMap<Int, String> = linkedMapOf(1 to "x", 2 to "y", -1 to "zz")
println(map) // {1=x, 2=y, -1=zz}
//sampleEnd
}

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/linked-map-of.html