Wednesday 8 August 2012

how to use map.entry in java example

Here,How to split  HashMap values  using Map and set interface..........

//package OtherHashMapExamples;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class MapUsageExample {

    public static void main(String[] args) {
       
        HashMap hm = new HashMap();
       
        hm.put("Hari" , new Integer(50));
        hm.put(" Kumar", new Integer(30));
        hm.put("Daya", new Integer(60));
        //hm.put("Krishnan", new Integer(70));
       
        Set set = hm.entrySet();
        //System.out.println(" hm.entrySet() : " + set);
       
        Iterator it = set.iterator();
       
        while(it.hasNext()) {
       
            //System.out.println("it Values :  " + it.next());
            Map.Entry<String, Integer> mapMe = (Map.Entry) it.next();
           
            System.out.println(" Mapped Values from Iterator Key : " + mapMe.getKey());
            System.out.println(" Mapped Values from Iterator Values : " + mapMe.getValue());
           
           
        }
        int addValue =  ((Integer) hm.get("Hari")).intValue();
        hm.put("Hari",new Integer(addValue + 450));
        System.out.println( " Hari new Name is : " + hm.get("Hari"));
       

    }

}

No comments:

Post a Comment

Complete Details about eLitmus pH Test at Rs:699/- Share your java material and fresher interview Information for us to Help Others... mail to : vhkrishnan.v@gmail.com