
public class HashTable {
public static void main(String args[]){
HashMap hm=new HashMap(); hm.put(new Integer(2), "Two"); hm.put(new Integer(1), "One"); hm.put(new Integer(3), "Three"); hm.put(new Integer(4), "Four");
Set s=hm.entrySet();
Iterator it=s.iterator();
while(it.hasNext())
{
Map.Entry m =(Map.Entry)it.next();
m.getKey();
// String value=(String)m.getValue();
System.out.println("The Key is:"+Key+" The Value is:");//+value);
}
}
}
i got an error in the "Key" variable..java.lang error please tell me the solution..

We have modified your code. Here is your code:
import java.util.*;
public class HashTable {
public static void main(String args[]){
HashMap hm=new HashMap();
hm.put(new Integer(2), "Two");
hm.put(new Integer(1), "One");
hm.put(new Integer(3), "Three");
hm.put(new Integer(4), "Four");
Set s=hm.entrySet();
Iterator it=s.iterator();
while(it.hasNext()){
Map.Entry m =(Map.Entry)it.next();
System.out.println("The Key is:"+m.getKey()+" The Value is:"+m.getValue());
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.