Dear all,
I have stuck with one problem.
I have taken one Hashmap, Performing some input operation,remove operation on it.
So after performing remove operation, i want value of 2 successive key in two different array.
Also i want to match 1st key's value with all other keys' value.
Like 1st key value matched with 2nd kay value,then 3rd key value upto last key
Again 2nd key value matched with 3rd kay value,then 4th key value upto last key.
I ahve also make some code but it's not working properly.
Here "m1" is my hash map.Originally there were 20 key value pair, after performing operation there will bw only 9 kay value pair.
So i have do following thing,but it only iterates for first key only.
My question is:How to iterate it through all key?
Map<Integer,String[]> m1 = new HashMap<Integer,String[]>();
//defines map m1
loc[0] = 1;
Set s1 = m1.keyset();
Iterator it1 = s1.iterator();
Iterator it2 = s1.iterator();
System.out.println(s1);
//it prints all the keys available in hashmap m1.
while(it1.hasNext()
{
String[] a1 = (String[])m1.get(it1.next());
//it gives the value of 1st key in m1
while(it2.hasNext())
{
String[] a2 = (String[])m1.get(it2.next());
//it gives the value of 2nd kay from map m1
if(a2[loc[0]]==a1[loc[0]])
{
System.out.println("Matched");
}
else
{
System.out.println("Matched");
}
}
}
It will run for inside iterator it2 for 8 times,but when it comes to next kaey of it1,it2 loop will be stopped.
so how to solve this?
Thank you.