/** * @author lautturi.com * Java example: java iterate hashmap/map */ import java.util.*; public class Lautturi { public static void main(String[] args) { Map <String, Integer> map = new HashMap<>(); map.put("Apple", 1); map.put("Banana", 4); map.put("Cherry", 7); map.put("Orange", 25); for (Map.Entry<String, Integer> entry : map.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue()); } } }
output:
Apple:1 Cherry:7 Orange:25 Banana:4