Category Archives: HashMap

Put,Remove,Sort,iterate,Get & other methods of HashMap (example)

What is HashMap in java? HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations (get and put). HashMap based implementation is not thread safe. HashMap must synchronized externally, If multiple threads access a hashmap concurrently. Program to demonstrate following methods of HashMap. Remove put Sort Iterate Get Contains And… Read More »

putIfAbsent method of HashMap in java (with example)

HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations (get and put). HashMap based implementation is not thread safe. HashMap must synchronized externally, If multiple threads access a hashmap concurrently putIfAbsent method is defined in Map interface. putIfAbsent method is used to add entry to HashMap, if its not… Read More »

Sort HashMap by keys in java (ascending & descending order)

What is HashMap in java? HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations (get and put). HashMap based implementation is not thread safe. HashMap must synchronized externally, If multiple threads access a hashmap concurrently. Sort the HashMap by keys in ascending & descending order. Map<String, String> mapSportsPersonality =… Read More »

Remove elements/string objects from HashMap collection by key (Java/example)

HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations like get & put. HashMap based implementation is not thread safe. In multi-threading environment, HashMap should be synchronized externally. If multiple threads access a hashmap concurrently then HashMap must synchronized externally. 1. Methods to remove element or objects from HashMap collection… Read More »

Iterate or loop HashMap using java8 (with example)

What is HashMap in java? HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations (get and put). HashMap based implementation is not thread safe. HashMap must synchronized externally, If multiple threads access a hashmap concurrently.Iterate or loop through the HashMap using following methods: Iterate HashMap using forEach (java 8) Iterate… Read More »