Is there a difference between a Scala Map
and a HashMap
? I am using the scala.collection.immutable.HashMap
.
Scala HashMap is used to store objects and it take the object in the form of key value pair. For every value there should be one key associated with it. Scala collection contains this Hashmap and it is the implementation of MAP.
HashMap does not maintain any insertion order of its elements hence it is quicker than Map. In contrast to Map, HashMap can hold duplicate values. It's possible to implement the Map interface by utilizing its implementing classes. Hashmap is all about implementing the Map Interface.
Key Differences between Map and HashMapThe Map is an interface, and HashMap is a class of the Java collection framework. The Map interface can be implemented by using its implementing classes. In comparison, the HashMap class implements the Map interface. The Map contains unique key-pair values.
HashMap is a part of Scala Collection's. It is used to store element and return a map. A HashMap is a combination of key and value pairs which are stored using a Hash Table data structure. It provides the basic implementation of Map.
scala.collection.immutable.Map
is the interface for immutable maps while scala.collection.immutable.HashMap
is a concrete implementation.
Creating with Map()
or Map.empty
gives a special empty singleton map, with Map(a -> b)
with up to 4 pairs yields specialized classes for such small maps, and 5 and upwards gives you scala.collection.immutable.HashMap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With