difference between hashmap and treemap java code example

Example 1: difference between hashmap and map java

Hash map: 

	-> It is the implementation of map interface.
	-> It can contain null values and keys.
	-> It doesn't maintain input order.

Map: 

	-> It is an interface
	-> Map has two implementation
	-> Tree Map
	-> Hash Map
	-> Tree Map maintains the input order .
	-> It will not allow any null values.
	-> Duplicate keys are not allowed in the map

Example 2: treemap vs hashmap

- TreeMap doesn't have null key and keys are sorted
 Can contain only unique keys and keys are sorted in ascending order.
 
 v- HasHMap can have null key, order is not guaranteed

Tags:

Java Example