i have a problem in iterating hashmap..
it gives me values in reverse order...why so..please help me...
here is my code..
cart="1.1,2.2,3.3,1.1";// cart variable
String[] cart_items=cart.split(",");// spliting cart by ' , '
HashMap<String,Integer> hashmap=new HashMap(); // create a new hashmap
for(String i:cart_items)// iterate through cart_items
{
if(hashmap.containsKey(i)) //if hashmap contains key increment value by 1
{
f+=1;
hashmap.put(i,f);
}
else
{
f=1;
hashmap.put(i, f); // if hashmap doesnt contain key put its values as 1
}
}
//now i want to iterate through this hashmap....
for(Object j:hashmap.keySet() )
{
out.println("key=" + i + " and value= " + hahsmap.get(i) );
}
/////////////// now this should give me output as..
key=1.1 and value=2
key=2.2 and value=1
key=3.3 and value=1
////////////but it gives me output as....
key=3.3 and value=1
key=2.2 and value=1
key=1.1 and value=2
/////////////
please help me why this is giving me such output..........................