kotlin.collections.hashMapOf

hashMapOf

inline fun <K, V> hashMapOf(): HashMap<K, V>

Platform and version requirements: Kotlin 1.1

Returns an empty new HashMap.

fun <K, V> hashMapOf(vararg pairs: Pair<K, V>): HashMap<K, V>

Returns a new HashMap with the specified contents, given as a list of pairs where the first component is the key and the second is the value.

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

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

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

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部