怎样取出List中对象的值?

hcqqkk 2007-08-30 02:40:55
怎样取出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>取值。谢谢。
...全文
1134 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiuqiupeng 2007-09-02
  • 打赏
  • 举报
回复
Object obect = (Object) alist.get(i);
OopsJeff 2007-08-31
  • 打赏
  • 举报
回复
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....);
}
}
jiu_yy 2007-08-31
  • 打赏
  • 举报
回复

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());
}
}
awusoft 2007-08-30
  • 打赏
  • 举报
回复
晕啊,你怎么这样用集合啊...那你是没办法取一个对像出来的啊,只能是String了嘛.都没有Resource存在了,只有它的一些值.

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() ; ){
String str = (String)it.next();//不知道你当时是怎么样Add的
log.info(bean.get....);
}
}
hcqqkk 2007-08-30
  • 打赏
  • 举报
回复
bit1010 2007-08-30
  • 打赏
  • 举报
回复
不知道你的这句话log.info(ite.next());会不会对结果有影响,因为这样,其实,list多next了一下。

这种问题,使用调试跟踪一下,一下子就出结果了。
hcqqkk 2007-08-30
  • 打赏
  • 举报
回复
谢谢,可是。那个list 一行如{1,"我","123@1.com","null"}
其中第四个元素"null"不是在 1,"我","123@1.com" 的对像Resource.java中的。。。所以就不知道怎样拿这些复合元素。
awusoft 2007-08-30
  • 打赏
  • 举报
回复
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....);
}
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧