Java hashmap map iteration

http‮s‬://www.lautturi.com
Java hashmap map iteration
/**
 * @author lautturi.com
 * Java example: Java hashmap map iteration
 */

import java.util.*;
import java.util.Map.Entry;

public class Lautturi {
    
	public static void main(String[] args) {
		
		Map<String, Integer> map = new HashMap<>();
		
		map.put("Apple", 21);
		map.put("Banana", 12);
		map.put("Cherry", 15);
		map.put("Orange", 35);	

		 // using for-each loop for iteration 
        for (Map.Entry<String,Integer> entry : map.entrySet())
            System.out.println("Key = " + entry.getKey() +
                             ", Value = " + entry.getValue());

		
	}
}

output:

Key = Apple, Value = 21
Key = Cherry, Value = 15
Key = Orange, Value = 35
Key = Banana, Value = 12
Created Time:2017-09-08 14:39:47  Author:lautturi