title: Iterate over all unique two-element combinations
body: <p>I need to iterate over all combinations of two elements: in a set [1,2,3,4] I want to iterate over [(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)]. Is there an existing tool to do so?</p>
  
  <pre><code>// Not what I need, works wrong!
  for (Object o1 : set) {
    for (Object o2 : set) {
      if (o1 == o2) continue;
      ...
    }
  }
  </code></pre>
  
  <p>This code would do twice more operations than needed, because each object will be visited in both loops. </p>
  
  <p>It is trivial to write my own method for that, I just don't want to invent the wheel. I'd expect to find this in Guava or Collections API, but didn't find such functionality.</p>