HashMap, TreeMap Classes in java.util: Types of constructors

HashMap Class: HashMap Class implements Map interface by using hash table. It extends AbstractMap class. There is no order followed by the elements of Hashmap. Types of constructors defined by HashMap:

Type-1: To create a default Hash map.

HashMap( )

Type-2: By using elements x.

HashMap(Map x)

Type-3: By using capacity

HashMap(int cap)

Type-4: By using capacity and fill Ratio.

HashMap(int cap, float fr)

TreeMap Class: TreeMap Class implements SortedMap and is used to store key and value pairs in a sorted ascending order of keys. It extends AbstractMap class. TreeMap provides fast access and retrieval of values.

Types of constructors in TreeMap Class:

Type-1: To create an empty TreeMap.

TreeMap( )

Type-2: Create a empty Tree map sorted by using comparator.

TreeMap(Comparator com)

Type-3: By using elements x.

TreeMap(Map x)

Type-4: Create a Tree map with entries of sorted map.

TreeMap(SortedMap s)

Leave a Reply