How do you search for a key in a HashMap
? In this program, when the user enters a key the code should arrange to search the hashmap for the corresponding value and
To decalare the hashMap use this:
HashMap hm=new HashMap();
To enter the elements in the HashMap:
hm.put(1,"January");
hm.put(2,"Febuary");
before searching element first check that the enter number is present in the hashMap for this use the method containsKey() which will return a Boolean value:
if(hm.containsKey(num))
{
hm.get(num);
}