title: How to compare elements of a list using streams?
body: <p>For example, I need to iterate through custom list <code>List&lt;Model&gt;</code> and compare items in it. So with <code>for</code> loop it would look like this</p>
  
  <pre><code>for(int i = 0; i &lt; list.size()-1; i++) {
      for (int j = i + 1; j &lt; list.size(); j++) {
          if (list.get(i).getSomeItem().equals(list.get(j).getSomeItem()){
                  /*modify the list using*/
                  list.get(j).setSomeOtherItem(list.get(i).getSomeItem()+list.get(j).getSomeItem());
          }
      }
  }
  </code></pre>
  
  <p>But how to get same result with streams or <code>forEach()</code> ? I'm trying to make something like this </p>
  
  <pre><code>for (Model i : list){
      for (Model j : list){
          if(i.getSomeItem.equals(j.getSomeItem()){
              /*same logic as in for loop*/
          }
      }
  }
  </code></pre>
  
  <p>or this </p>
  
  <pre><code> List&lt;StorageModel&gt; newList = list.stream()
             .filter(item -&gt; item.getSomeItem.equals...)
  </code></pre>
  
  <p>So the problem is that with <code>forEach</code> both loops starts from the same element and compare the same items. With streams I don't event know how to get next value. Is the any way to do this ?</p>