Difference between HashMap and Map in Java..?
Solution 1
Map
is an interface, i.e. an abstract "thing" that defines how something can be used. HashMap
is an implementation of that interface.
Solution 2
Map<K,V>
is an interface,
HashMap<K,V>
is a class that implements Map
.
you can do
Map<Key,Value> map = new HashMap<Key,Value>();
Here you have a link to the documentation of each one: Map, HashMap.
Solution 3
Map
is an interface; HashMap
is a particular implementation of that interface.
HashMap uses a collection of hashed key values to do its lookup. TreeMap will use a red-black tree as its underlying data store.
Solution 4
Map
is an interface in Java. And HashMap
is an implementation of that interface (i.e. provides all of the methods specified in the interface).
Solution 5
HashMap
is an implementation of Map
. Map is just an interface for any type of map.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on July 08, 2020Comments
-
Admin almost 4 years
Possible Duplicate:
Java - HashMap vs Map objectsI want to know the difference between
HashMap
andMap
in java..??