This may be an already asked question but I don't find the answer I need.
I have a Set with objects like
public class MyObject {
private LocalDate dateBeginning;
private LocalDate dateEnd;
public boolean overlap(MyObject otherDate) { /*code to check overlapping*/ }
}
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.
How can we do this with streams and lambdas in Java 8?
I have already tried with reduction()
and filter()
but none of them seem to work
.filter((obj1, obj2) -> { if (obj1.overlap(obj2)) return true;}) //doesn't work