Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Map vs HashMap

Is there a difference between a Scala Map and a HashMap? I am using the scala.collection.immutable.HashMap.

like image 883
jstnchng Avatar asked Jul 28 '15 19:07

jstnchng


People also ask

Is scala map a 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.

Which is better map or HashMap?

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.

Whats the difference between a map and a HashMap?

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.

What is scala HashMap?

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.


1 Answers

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

like image 52
johanandren Avatar answered Sep 22 '22 13:09

johanandren