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"));
}
}
//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