Here is my code to store the data into HashMap and display the data using iterator
public static void main(String args[]) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("aaa", "111");
hm.put("bbb", "222");
hm.put("ccc", "333");
hm.put("ddd", "444");
hm.put("eee", "555");
hm.put("fff", "666");
Iterator iterator = hm.keySet().iterator();
while (iterator.hasNext()) {
String key = (String) iterator.next();
String val = hm.get(key);
System.out.println(key + " " + val);
}
}
But it is not displaying in the order in which I stored. Could someone please tell me where am I going wrong? How can I get the elements in the order?