 <p>Create a new <code>Map</code> with refnum as key and qty as value.</p> <pre><code>Map&lt;String,Integer&gt; qtyMap=new HashMap&lt;String,Integer&gt;(); </code></pre> <p>while iterating, try</p> <pre><code>String refNum=transItem.getRefNum(); // Mark for removal ? if this is not the first item in the list with the refnum boolean remove=true; Integer currentQty=qtyMap.get(refNum); if(currentQty==null){ currentQty=0; // this doesnt exist already in the map, this is the first item with this reference // number in the list, so you should keep this without removing remove=false; } currentQty=currentQty+transItem.getQty(); qtyMap.put(refNum,currentQty); // if the remove is true then remove this item from the list. if(remove){ groupTransItems.remove(); } </code></pre> <p>This will sum up the qty for refnum's in the map and once your iteration is over, the map will have the sums of quantities for each refnum. You will have to iterate the list once more to set the current qty to each item from the map [EDIT] :- Added the iterating time removal.</p>