Hi I am trying to iterate HashMap for two times with same Iterator object. The first time it is working fine but the second while iterating loop is not working. From the below code I am trying to iterate HashMap my integer array length. But it is entering into the interger array loop but it is not entering into the HashMap while loop at the second time. Could anyone please help me on this issue. And please tell me how to iterate HashMap at many times.
HashMap tempMap = new HashMap();
int [] tempint = {0005,0001,0001,0005,0002,0003,0004,0002,0003};
tempMap.put("A","0005");
tempMap.put("B","0004");
tempMap.put("C","0001");
tempMap.put("D","0002");
tempMap.put("E","0003");
tempMap.put("F","0006");
Iterator it1 = tempMap.keySet().iterator();
while(it1.hasNext()){//First time it is entering into the HashMap while loop
String key = (String)it1.next();
String value = (String)tempMap.get(key);
for(int i=0;i<tempint.length;i++){
System.out.println("Working fine for First iterator");
}
}
java.util.Arrays.sort(tempint);
//Iterator it2 = tempMap.keySet().iterator();
for(int j=0;j<tempint.length;j++){
String temseg = "000"+tempint[j];
while(it1.hasNext()){ //Here it is not entering into the loop.
String key = (String)it1.next();
String value = (String)tempMap.get(key);
if(temseg.equals(value)){
System.out.println("EQUAL==================="+value);
}
}
}