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 /loop HashMap collection having string objects (Java8/ example)

1. What is HashMap collection in java? HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations like get & put. HashMap is not not thread safe. HashMap must synchronized externally, If multiple threads access the hashmap concurrently. We will iterate or loop through HashMap collection using following methods: Iterate… Read More »

Add or put elements/string objects to HashMap collection (java /example)

Given a HashMap collection in java, We would like to add or put elements/objects to HashMap. HashMap is Hash table based implementation of the Map interface. HashMap provides constant-time performance for the basic operations like get & put. HashMap is not not thread safe. HashMap must synchronized externally, If multiple threads access the hashmap concurrently. HashMap collection has… Read More »