Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created October 12, 2020 13:25
Show Gist options
  • Save ch8n/9f90468d5ca0fcbcb938451fd7b1942c to your computer and use it in GitHub Desktop.
Save ch8n/9f90468d5ca0fcbcb938451fd7b1942c to your computer and use it in GitHub Desktop.
hashMapOf definations kotlin
fun <K, V> hashMapOf(vararg pairs: Pair<K, V>): HashMap<K, V>
= HashMap<K, V>(mapCapacity(pairs.size)).apply { putAll(pairs) }
// this factory function takes pair and uses HashMap's second constructor which
// start off with the object capacity as the number of pairs passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment