access each key and value in a hashmap java
// access each key and corresponding value in a hashmap HashMapmap = new HashMap<>(); for(Map.Entry entry : map.entrySet()){ entry.getKey(); entry.getValue(); }
Here is what the above code is Doing:
1. Create a new HashMap
2. Iterate through each entry in the HashMap
3. Get the key and value of each entry