I have two HashSets with same type of objects. My search criteria is like, search in first set and if not present then search in another set. I had tried with Stream layer with following steps as given below
Set<MyObject> firstSet = new HashSet<>();
Set<MyObject> secondSet = new HashSet<>();
and these two sets are having some values.
Predicate<MyObject> match = myObject -> StringUtils.equals(myValue, myObject.getMyValue());
firstSet.values().stream().filter(match).findFirst()
.orElse(secondSet.values().stream().filter(match)
.findFirst().orElseThrow(()-> new MyException()));
My matching object is in First Set and i have tried to get it by manually and i got it... but using the above iteration, i always get the exception even when the first set has the matched object. Kindly correct me.. thanks is advance.