title: Java 8: How to compare all elements of a Set
body: <p>This may be an already asked question but I don't find the answer I need.</p>
  
  <p>I have a Set with objects like</p>
  
  <pre><code>public class MyObject {
      private LocalDate dateBeginning;
      private LocalDate dateEnd;
  
      public boolean overlap(MyObject otherDate) { /*code to check overlapping*/ }
  }
  </code></pre>
  
  <p>I need to check whether the Set contains to elements that overlap each other. In "old-java" I would go through the set twice and check for all combinations that exist and then break or return when I find it.</p>
  
  <p>How can we do this with streams and lambdas in Java 8?</p>
  
  <p>I have already tried with <code>reduction()</code> and <code>filter()</code> but none of them seem to work</p>
  
  <pre><code>.filter((obj1, obj2) -&gt; { if (obj1.overlap(obj2)) return true;}) //doesn't work
  </code></pre>