通过Java中的ArrayLists的ArrayList进行迭代 [英] Iterate through an ArrayList of ArrayLists in Java

查看:127
本文介绍了通过Java中的ArrayLists的ArrayList进行迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下ArrayList ...

I have the following ArrayList...

ArrayList<ArrayList<Integer>> row1 = new ArrayList<ArrayList<Integer>>();

以下的arraylists被加入....

The following arraylists are added to it....

row1.add(cell1);
row1.add(cell2);
row1.add(cell3);
row1.add(cell4);
row1.add(totalStockCell);

我想遍历arraylist row1并打印内容。

I want to iterate through the arraylist row1 and print the contents.

循环中的循环会在这里工作吗?

Would a loop within a loop work here?

例如

while(it.hasNext()) {

//loop on entire list of arraylists
    while(it2.hasNext) {
      //each cell print values in list

          } }


推荐答案

这是你这样做的规范方式:

This is the canonical way you do it:

for(List<Integer> innerList : row1) {
    for(Integer number : innerList) {
        System.out.println(number);
    }
}

这篇关于通过Java中的ArrayLists的ArrayList进行迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆