I tried to iterate over hashmap in Java, which should be a fairly easy thing to do. However, the following code gives me some problems:
HashMap hm = new HashMap(
Iterator through keySet
will give you keys. You should use entrySet
if you want to iterate entries.
HashMap hm = new HashMap();
hm.put(0, "zero");
hm.put(1, "one");
Iterator iter = (Iterator) hm.entrySet().iterator();
while(iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
System.out.println(entry.getKey() + " - " + entry.getValue());
}