This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kotlin signature | |
typealias LinkedHashMap<K, V> = LinkedHashMap<K, V> | |
// Java signature | |
class LinkedHashMap<K,V> | |
extends HashMap<K,V> | |
implements Map<K,V> | |
// Available Constructors | |
Java LinkedHashMap has three constructors | |
- LinkedHashMap() | |
- LinkedHashMap(int initialCapacity) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Directly use the 4th constructor example | |
val contact = mapOf("chetan" to "[email protected]") | |
val hashMapOfContact = HashMap(contact) | |
//Or create and add all entries | |
val hashMapOfContact = HashMap<String,Int>() | |
hashMapOfContact.putAll(contact) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val hashMap = HashMap<String,Int>() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <K, V> hashMapOf(): HashMap<K, V> = HashMap<K, V>() | |
// hashmapOf directly create HashMap object default constructor | |
// Java HashMap default constructor create HashMap with | |
// * inital capacity 16 and * LoadFactor 0.75 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kotlin Standard Library function | |
fun <K, V> hashMapOf(): HashMap<K, V> | |
fun <K, V> hashMapOf(vararg pairs: Pair<K, V>): HashMap<K, V> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kotlin signature | |
typealias HashMap<K, V> = HashMap<K, V> | |
// Java signature | |
class HashMap<K,V> | |
extends AbstractMap<K,V> | |
implements Map<K,V>, Cloneable, Serializable | |
// AbstractMap<K,V> is a skeletal implementation of the Map interface, | |
// Java's Map<K,V> is very close to MutableMap<K,V> than kotlin's Map<K,V> | |
// i.e it contains mutable opertaions internally, though use structures named | |
// similar to Kotlin's Map<K,V> like Map.Entry but are infact Mutable Entry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <K, V> mutableMapOf(vararg pairs: Pair<K, V>): MutableMap<K, V> | |
= LinkedHashMap<K, V>(mapCapacity(pairs.size)) | |
.apply { putAll(pairs) } | |
// resolved with LinkedHashMap only |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <K, V> mutableMapOf(): MutableMap<K, V> = LinkedHashMap() | |
// mutableMapOf is resolved using LinkedHashMap | |
// as discussed earlier Linked HashMap signature | |
class LinkedHashMap<K, V> : MutableMap<K, V> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kotlin Standard Library function | |
fun <K, V> mutableMapOf(): MutableMap<K, V> | |
fun <K, V> mutableMapOf(vararg pairs: Pair<K, V> ): MutableMap<K, V> |