/** * @author lautturi.com * Java example: traverse/iterate over/through dictionary in java */ import java.util.*; 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, "l autturi.com"); dict.put(5, "JavaScript"); Enumeration<Integer> e = dict.keys(); while (e.hasMoreElements()) { Integer key = e.nextElement(); String value = dict.get(key); System.out.print("key:" + key); System.out.println(" value:" + value); } } }
output:
key:5 value:JavaScript key:4 value:l autturi.com key:3 value:C++ key:2 value:Python key:1 value:Java