title: Filtering list values, should I create a new list or delete values from the original one
body: <p>Say I have a list that contains either single values, or value ranges. Now if I add a new value or a range to this list, it might overlap with none to multiple of the current values/ranges. All these overlapping objects should be combined to create a new instance, that should be added to the list, meanwhile the objects that got included in the new instance need to be deleted from the original list.</p>
  
  <p>So my question is, should I really delete those objects from the list or create a new list on every iteration. That is, put to code:</p>
  
  <p><strong>Solution 1</strong></p>
  
  <pre><code>for (Range newObj : newItems){
    Iterator it = oList.iterator();
    while (it.hasNext()){
      Range o = it.next();
      if (canCombine(newObj, o)){
        newObj = combine(newObj, o);
        it.remove();
      }
    }
    oList.add(newObj);
  }
  </code></pre>
  
  <p><strong>Solution 2</strong></p>
  
  <pre><code>for (Range newObj : newItems){
    List newList = new ArrayList();
    for (Range o : oList){
      if (canCombine(newObj, o)){
        new = combine(newObj, o);
      } else {
        newList.add(o);
      }
    }
    newList.add(newObj);
    oList = newList;
  }
  </code></pre>
  
  <p>Maybe another solution is even better. If so, kindly let me know.</p>