hashMapOf

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

Returns an empty new HashMap.

Since Kotlin

1.1

Samples

import samples.*
import kotlin.test.*
import java.util.*
fun main() { 
   //sampleStart 
   val map = hashMapOf<Int, Any?>()
assertTrue(map.isEmpty())

map[1] = "x"
map[2] = 1.05
// Now map contains something:
assertPrints(map, "{1=x, 2=1.05}") 
   //sampleEnd
}

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.

Samples

import samples.*
import kotlin.test.*
import java.util.*
fun main() { 
   //sampleStart 
   val map: HashMap<Int, String> = hashMapOf(1 to "x", 2 to "y", -1 to "zz")
assertPrints(map, "{-1=zz, 1=x, 2=y}") 
   //sampleEnd
}