title: How to avoid multiple for loops when traversing all the nested child objects in Java?
body: <p>I know that traversal through objects in nested loops is a bad practice. I have come across a situation like this and having a hard time to find a way to avoid the nested loops.</p>
  
  <p>I have an item list. Each item can have several locations.</p>
  
  <pre><code>&gt; Item01 -&gt; location01, location02, location03
  &gt; Item02 -&gt; Location04, location05
  ....
  </code></pre>
  
  <p>My code is something like below</p>
  
  <pre><code>        List&lt;Item&gt; itemList = getItemList();
          RenderItem renderItem = new RenderItem();
          List&lt;RenderItem&gt; renderItemList = new ArrayList&lt;RenderItem&gt;();
  
          for (Item item: itemList){
  
              for (ItemLocation itemLocation : item.getLocations() ){
  
                  renderItem = new RenderItem();
                  renderItem.setItem(item);
                  renderItem.setLocation(itemLocation);
                  renderItemList.add(renderItem);
  
              }
          }
  </code></pre>
  
  <p>I need to traverse all the location and create a renderItemList. </p>
  
  <p>How can I get rid of the nested loops? what strategies should I use? Please advice. [Note: I can only use Java 7]</p>