Iterate over a list and put data in hashmap

Posted by sarah on Stack Overflow See other posts from Stack Overflow or by sarah
Published on 2010-05-17T09:21:42Z Indexed on 2010/05/17 9:30 UTC
Read the original article Hit count: 190

Filed under:

I am having a list where i need to loop over it and put its data in hashmap,i am using this approach

 for(int i=0;i<list.size();i++)
 {
            HashMap hMap=new HashMap();
            hMap.put("Data", list);
 }

But when i need to read the value from hMap i am doing in this way

Collection c = hMap.values();
Iterator itr = c.iterator();

while(itr.hasNext())
{
    System.out.println("next val is--"+itr.next());
}

next vali is--- is printed in com.bean.xyz@23032bc[id=1] format ,i need the exact data,how will i do this ?

© Stack Overflow or respective owner

Related posts about java