Answers for "HashMap to store key and value pair."

0

HashMap to store key and value pair.

import java.util.*;  
public class hashmapeg1{  
 public static void main(String args[]){  
   HashMap<Integer,String> map=new HashMap<Integer,String>();//Creating HashMap    
   map.put(1,"Cat");  //Put elements in Map  
   map.put(2,"Dog");    
   map.put(3,"Markhor");   
   map.put(4,"Peacock");   
       
   System.out.println("Iterating Hashmap...");  
   for(Map.Entry m : map.entrySet()){    
    System.out.println(m.getKey()+" "+m.getValue());    
   }  
}  
}
Posted by: Guest on May-10-2022

Code answers related to "HashMap to store key and value pair."

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language