Difference between HashMap and Map in Java..?

JavaHashmap

Java Problem Overview


> Possible Duplicate:
> Java - HashMap vs Map objects

I want to know the difference between HashMap and Map in java..??

Java Solutions


Solution 1 - Java

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 - Java

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 - Java

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 - Java

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 - Java

HashMap is an implementation of Map. Map is just an interface for any type of map.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1252812View Question on Stackoverflow
Solution 1 - JavaLars KotthoffView Answer on Stackoverflow
Solution 2 - JavaWalterMView Answer on Stackoverflow
Solution 3 - JavaduffymoView Answer on Stackoverflow
Solution 4 - JavasmessingView Answer on Stackoverflow
Solution 5 - JavaaseychellView Answer on Stackoverflow