怎样取出List中对象的值?
怎样取出List中对象的值?
List alist = ud.getResourceListByUserId( "admin ");
for(Iterator ite = alist.iterator() ; ite.hasNext() ; ){
List blist = (List)ite.next();
log.info(ite.next());
for(Iterator it = blist.iterator() ; it.hasNext() ; ){
Object obj = (Object)it.next();
log.info(obj);
}
}
但是运行不成功,请问大家怎样取出List中对象的值,就是类似List <List> 取值。谢谢。
------解决方案--------------------List alist = ud.getResourceListByUserId( "admin ");
for(Iterator ite = alist.iterator() ; ite.hasNext() ; ){
List blist = (List)ite.next();
log.info(ite.next());
for(Iterator it = blist.iterator() ; it.hasNext() ; ){
Object obj = (Object)it.next();//这里不用Object啊,用具体放进去的类型啊
比如MyBean bean = (MyBean)it.next();
log.info(bean.get....);
}
}
------解决方案--------------------不知道你的这句话log.info(ite.next());会不会对结果有影响,因为这样,其实,list多next了一下。
这种问题,使用调试跟踪一下,一下子就出结果了。
------解决方案-------------------- xxxBean.setXxx( "fdsa ");
list.add(xxxBean);
List list = xxx.getList();
if(!list.isEmpty){
for(int i = 0 ; i < list.size() ; i++){
XxxBean xxxBean = (XxxBean)list.get(i);
System.out.println(xxxBean.getXxx());
}
}
------解决方案--------------------List alist = ud.getResourceListByUserId( "admin ");
for(Iterator ite = alist.iterator() ; ite.hasNext() ; ){
List blist = (List)ite.next();
log.info(ite.next());
for(Iterator it = blist.iterator() ; it.hasNext() ; ){
Object obj = (Object)it.next();//这里不用Object啊,用具体放进去的类型啊
比如MyBean bean = (MyBean)it.next();
log.info(bean.get....);
}
}
------解决方案--------------------Object obect = (Object) alist.get(i);