java loop through keys of hashmap

h‮w//:sptt‬ww.lautturi.com
java loop through keys of hashmap
/**
 * @author lautturi.com 
 * Java example: java loop through keys only in hashmap
 */ 

import java.util.*;

public class Lautturi {
	public static void main(String[] args) {

		HashMap<Integer, String> map = new HashMap<Integer, String>();

		map.put(1, "Apple");
		map.put(2, "Banana");
		map.put(3, "Cherry");
		map.put(4, "Orange");
		map.put(5, "Lautturi");

		for (Integer key : map.keySet()) {
			System.out.println("key:"+key);
		}

	}
}

output:

key:1
key:2
key:3
key:4
key:5
Created Time:2017-10-03 23:17:50  Author:lautturi