Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

iterate hashmap entries

Map<Character, String> charType
            = new HashMap<Character, String>();
 
        // Inserting data in the hash map.
        charType.put('J', "Java");
        charType.put('H', "Hibernate");
        charType.put('P', "Python");
        charType.put('A', "Angular");
 
        // Iterating HashMap through forEach and
        // Printing all. elements in a Map
        charType.forEach(
            (key, value)
                -> System.out.println(key + " = " + value));
		
		// or 
		// using for loop to iterate the map entry sets
		for (Map.Entry<String,String> mapElement : charType.entrySet()) {
            String key = mapElement.getKey();
 
            // Adding some bonus marks to all the students
            String value = mapElement.getValue();
 
            // Printing above marks corresponding to
            // students names
            System.out.println(key + " : " + value);
        }
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #iterate #hashmap #entries
ADD COMMENT
Topic
Name
2+6 =