How to itreate objects in Map?
>> Thursday, May 26, 2011
Map: It can be used to store group of objects in the of name value pairs.
package com.centris.atr.bean;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class IterateMap {
public static void main(String[] args) {
Map m=new HashMap();
m.put(1, "bhaskar");
m.put(2,"Ajantha");
m.put(3, "prathap");
Set s=m.entrySet();
Iterator it =s.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}
package com.centris.atr.bean;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class IterateMap {
public static void main(String[] args) {
Map m=new HashMap();
m.put(1, "bhaskar");
m.put(2,"Ajantha");
m.put(3, "prathap");
Set s=m.entrySet();
Iterator it =s.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}
0 comments:
Post a Comment