/** * @author lautturi.com * Java example: iterate through dictionary in java */ public class Lautturi { public static void main(String[] args) { Dictionary<Integer, String> dict = new Hashtable<Integer, String>(); dict.put(1,"Java"); dict.put(2,"Python"); dict.put(3,"C++"); dict.put(4,"Perl"); dict.put(5,"JavaScript"); for (Map.Entry<Integer, String> entry :((Hashtable<Integer, String>) dict).entrySet()) { Integer key = entry.getKey(); String val = entry.getValue(); System.out.println(key+" "+val); } } }
output:
5 JavaScript 4 Perl 3 C++ 2 Python 1 Java