S
Sridhar
Consider the following snippet to display the contemts of a HashMap in
a sequential manner.
//temp2 is a hashmap
Set set2=temp2.entrySet();
Iterator iHash2=set2.iterator();
while(iHash2.hasNext()){
Map.Entry me2= (Map.Entry) iHash2.next();
System.out.println(me2.getKey());
}
I printed the order in which the elements were entered in the HashMap
and later printed the hashMap using the above algorithm... both are
different.... Any idea why??
I'm just printing the keys here. During insertion the order followed
for the key is
r1,s3,s2,s1
but when i print the hashmap the order is:
s2,s3,r1,s1
Since i need to use it sequentially later in the application, the order
is very important. I cant sort the hashmap too as keys have no relation
whatsoever.
Any pointers??
a sequential manner.
//temp2 is a hashmap
Set set2=temp2.entrySet();
Iterator iHash2=set2.iterator();
while(iHash2.hasNext()){
Map.Entry me2= (Map.Entry) iHash2.next();
System.out.println(me2.getKey());
}
I printed the order in which the elements were entered in the HashMap
and later printed the hashMap using the above algorithm... both are
different.... Any idea why??
I'm just printing the keys here. During insertion the order followed
for the key is
r1,s3,s2,s1
but when i print the hashmap the order is:
s2,s3,r1,s1
Since i need to use it sequentially later in the application, the order
is very important. I cant sort the hashmap too as keys have no relation
whatsoever.
Any pointers??