-3

我有ArrayList一个通用类型,如下所示:

List<abcparsepojo> xyzintrunsiveObjects = (List<abcparsepojo>)abcparseGetter.getObjects(file);

ArrayList当我想在控制台上打印它的内容时,如何迭代它?我已经交叉检查(在调试和检查时)它已经得到了内容。我可以for为此使用高级循环吗?

4

2 回答 2

3

Try

List<abcparsepojo> xyzintrunsiveObjects = (List<abcparsepojo>)abcparseGetter.getObjects(file);
for(abcparsepojo pojo: xyzintrunsiveObjects) {
    //do something with pojo
    System.out.println(pojo.getSomeProperty())
}
于 2013-05-02T03:32:39.610 回答
0

有两种方法可以做到这一点:

1.增强for循环

    List<abcparsepojo> xyzintrunsiveObjectsList = 
                             (List<abcparsepojo>)abcparseGetter.getObjects(file);
    for(abcparsepojo element: xyzintrunsiveObjectsList) {
       //use element here
    }

2.使用Iterator. 如果您想从中删除元素,这很有用List

List<abcparsepojo> xyzintrunsiveObjectsList = 
                             (List<abcparsepojo>)abcparseGetter.getObjects(file);
Iterator<abcparsepojo> pojoIterator = xyzintrunsiveObjectsList .iterator();
while(pojoIterator .hasNext()){
   abcparsepojo element = (abcparsepojo)pojoIterator.next();
   //use element here
}
于 2013-05-02T05:56:08.627 回答