Professional Documents
Culture Documents
Map Collection
Map Collection
Map Collection
HashMap:
HashMap<KeyType, ValueType> hashMap = new HashMap< KeyType, ValueType >();
TreeMap:
TreeMap<KeyType, ValueType> treeMap = new TreeMap< KeyType, ValueType >();
Replace KeyType with the desired key type, and ValueType with the desired value type.
LinkedHashMap:
LinkedHashMap<KeyType, ValueType> linkedHashMap = new LinkedHashMap< KeyType,
ValueType >();
Replace KeyType with the desired key type, and ValueType with the desired value type. For
example, you can use String as the key type and Integer as the value type.
# All The Methods:
However, each implementation also has some unique characteristics and additional methods:
HashMap: Provides constant-time performance for basic operations (such as put, get, and remove) on
average. It does not guarantee any particular order for the elements.
TreeMap: Maintains the keys in sorted order, either using the natural order of the keys or a custom
Comparator. It provides efficient operations for finding ranges and retrieving entries based on their
order.
LinkedHashMap: Maintains the order of elements based on the insertion order or access order (by
setting accessOrder to true in the constructor). It offers predictable iteration order.