Java Map and forEach

map,loop,forEach,iterator

loop a Map

public class Main {
	public static void main(String [] args){
		Map<String,Double> map = new HashMap<>();
		map.put("2330",309D);
		map.put("2317", 91.4);
		map.put("3008", 4345D);
		
		//iterator
		Set<String> set = map.keySet();
		Iterator<String> it = set.iterator();
		while (it.hasNext()) {
			String key = it.next();
			System.out.printf("key:%s,value:%s\n", key, map.get(key));
		}
		
		//forEach
		for (Map.Entry<String, Double> entry : map.entrySet()) {
			System.out.println("key:" + entry.getKey() + ",value:" + entry.getValue());
		}

		//lamda forEach
		map.forEach((u, v) -> System.out.println("key:" + u + ",value:" + v));
		
	}
}

Reference: