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

前端 未结 6 621
温柔的废话
温柔的废话 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:49

    You want to follow the same pattern as before:

    for (Type curInstance: CollectionOf) {
      // use currInstance
    }
    

    In this case it would be:

    for (Bullet bullet : gunList.get(2).getBullet()) {
       System.out.println(bullet);
    }
    

提交回复
热议问题