title: Spliting ArrayList into several ArrayLists based on variable
body: <p>I need to split an ArrayList containing primitive data types, String and ArrayLists to several ArrayLists based on a variable in this ArrayList.</p>
  
  <p>I have my ArrayList <code>purchaseOrderList</code> with "brand" of type String among many others. I want to split this ArrayList into as many new ArrayLists as I have different brands. I keep ending up in an infinite loop no matter how I do it.</p>
  
  <pre><code>ArrayList&lt;Brand&gt; brandList = new ArrayList&lt;Brand&gt;();
  
  brandList.add(new Brand(purchaseOrderList.get(0).getBrand()));
  for (int i = 0; i &lt; brandList.size(); i++) {
      for (Item item : purchaseOrderList) {
          if (brandList.get(i).getBrand().equals(item.getBrand())) {
              brandList.get(i).setItemList(item); //Add the items from the purchaseOrderList
          } else {
              brandList.add(new Brand(item.getBrand()));
          }
      }
  }
  </code></pre>
  
  <p>Any advice?</p>