title: How to Iterate Two Lists and compare the items within?
body: <p>I'm almost at the end of my final project in the university, I'm trying to control my inStock with my current Stock of articles. </p>
  
  <p>My stock contains the following attributes:</p>
  
  <pre><code>int idMercaderia;
  int cantidad;
  int idSucursal;
  </code></pre>
  
  <p>I have two lists that contains <code>Inventario</code> type <code>POJO</code>s: </p>
  
  <pre><code>List &lt;Inventario&gt; stock = new InventarioDAO().findAll();
  List &lt;Inventario&gt; inStock = new ArrayList &lt;Inventario&gt;();
  </code></pre>
  
  <p>Before persist in the database, I want to compare the attribute <code>idMercaderia</code> in both of 'em, if they're the same don't create another entry and just add the quantity <code>cantidad</code> to the current stock and do a <code>saveOrUpdate()</code> if not just create another entry.</p>
  
  <p>I'm really stuck in this part and currently run out of ideas after trying iterate both Lists but I can't figure out the stock thingy.</p>
  
  <p>Any help/code will be really appreciated.</p>