How to iterate through an ArrayList of Objects of ArrayList of Objects?

前端 未结 6 593
温柔的废话
温柔的废话 2020-12-24 01:18

Using an example:

Let say I have a class call Gun. I have another class call Bullet.

Class Gun has an

6条回答
  •  醉梦人生
    2020-12-24 01:33

    We can do a nested loop to visit all the elements of elements in your list:

     for (Gun g: gunList) {
       System.out.print(g.toString() + "\n   "); 
       for(Bullet b : g.getBullet() {
          System.out.print(g);    
       }
       System.out.println(); 
     }
    

提交回复
热议问题