Hash Map:
- Unordered and unsorted map.
- Hashmap is a good choice when we don’t care about the order.
- It allows one null key and multiple null values.
Example:
Public class Fruit{
Public static void main(String[ ] args){
HashMap<Sting,String> names =new HashMap<String,String>( );
names.put(“key1”,“cherry”);
names.put (“key2”,“banana”);
names.put (“key3”,“apple”);
names.put (“key4”,“kiwi”);
names.put (“key1”,“cherry”);
System.out.println(names);
}
}
Output:
{key2 =banana, key1=cherry, key4 =kiwi, key3= apple}
Duplicate keys are not allowed in Map.
It doesn’t maintain any insertion order and is unsorted.