How to iterate over a TreeMap? [duplicate]
Assuming type TreeMap<String,Integer> : for(Map.Entry<String,Integer> entry : treeMap.entrySet()) { String key = entry.getKey(); Integer value = entry.getValue(); System.out.println(key + ” => ” + value); } (key and Value types can be any class of course)