title: How to iterate through an ArrayList of Objects of ArrayList of Objects?
body: <p><strong>Using an example:</strong></p>
  
  <p>Let say I have a class call <code>Gun</code>.
  I have another class call <code>Bullet</code>.</p>
  
  <p>Class <code>Gun</code> has an ArrayList of <code>Bullet</code>.</p>
  
  <p>To iterate through the Arraylist of <code>Gun</code> ..instead of doing this:</p>
  
  <pre><code>ArrayList&lt;Gun&gt; gunList = new ArrayList&lt;Gun&gt;();
  for (int x=0; x&lt;gunList.size(); x++)
      System.out.println(gunList.get(x));
  </code></pre>
  
  <p>We can simply iterate through the ArrayList of <code>Gun</code> as such:</p>
  
  <pre><code>for (Gun g: gunList) System.out.println(g); 
  </code></pre>
  
  <p>Now, I want to iterate and print out all <code>Bullet</code> of my 3rd <code>Gun</code> object:</p>
  
  <pre><code>for (int x=0; x&lt;gunList.get(2).getBullet().size(); x++)  //getBullet is just an accessor method to return the arrayList of Bullet 
      System.out.println(gunList.get(2).getBullet().get(x));
  </code></pre>
  
  <p><strong>Now my question is:</strong> Instead of using the conventional for-loop, how do I printout the list of gun objects using the ArrayList iteration ?</p>