Java, J2EE & SOA Certification Training
- 29k Enrolled Learners
- Live Class
Java HashMap is a class which is used to perform operations such as inserting, deleting and locating elements in a map. We create a map, where we pass two kinds of values which are ‘key’ and ‘value’.
While using HashMaps, values will be put in HashMap and whenever the user retrieves a value, the key will be used in order to use the value.
The map is an interface that maps keys to the elements. Maps are unsorted and unordered. They allow one null key and multiple null values. The values are stored in key and value. One key or multiple values could be null in the entire HashMap. A key can be any object.
There are several methods available in HashMap
There are corresponding values for each key where values can be null in the HashMap also.
Creation of HashMap.
HashMap hashmap = new HashMap();
Here, we pass key and the value.
Displaying the value – Get an iterator
Iterator iterator = hashmap.entrySet().iterator();
Here, the values are present in the set so we use entrySet.
Along with the line:
Map.Entry entry=(Map.Entry) iterator.next();
Got a question for us? Mention them in the comments section and we will get back to you.