Wednesday, 18 January 2017

HashMap : PutMethod


import java.util.*;
public class PutMethod {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Map<Integer, String> map1 = new HashMap<>();
        map1.put(1, "One");
        map1.put(2, "Two");
        map1.put(3, "Three");
        map1.put(4, "Four");
        map1.put(5, "Five");
        map1.put(6, "Six");
        map1.put(7, "Seven");
        map1.put(8, "Eight");
       
        System.out.println("HashMap<k, v> full list (k=v) : "+map1);
       

        /*Set set = map1.entrySet();
       
        Iterator itr = set.iterator();
        while(itr.hasNext())
        {
            Map.Entry me = (Map.Entry)itr.next();
            System.out.print("Key : "+me.getKey());
            System.out.println(", Value : "+me.getValue());
           
        }*/
    }
}

No comments:

Post a Comment