This is my code.I am inserting a map into a list.but when I am directly adding a map into table.It is showing error.
import java.util.*;
class mapIn{
public static void main(String... a){
List<Map<Integer, String>> mapList = new ArrayList<Map<Integer,String>>();
mapList.add(new HashMap<Integer,String>().put(1,"Ram"));
mapList.add(new HashMap<Integer,String>().put(2,"Shyam"));
mapList.add(new HashMap<Integer,String>().put(3,"Shyam"));
for(Map m:mapList){
// for(Map.Entry e:m.entrySet()){
// System.out.println(e.getKey()+" "+e.getValue());
// }
Set set=m.entrySet();//Converting to Set so that we can traverse
Iterator itr=set.iterator();
while(itr.hasNext()){
//Converting to Map.Entry so that we can get key and value separately
Map.Entry entry=(Map.Entry)itr.next();
System.out.println(entry.getKey()+" "+entry.getValue());
}
}
}
}