I am looking for some object in map:
mapObjects.entrySet().stream().map(map -> map.getValue()).filter(predicateA)
When I find more then one item, I want to specify a second predicate to filter on some additional attribute. Is there some way I can do this in just one iteration of stream, or do I need to iterate once and when count > 1
then I need to iterate a second time with another predicate ?
For example, say I have list of persons. First I am looking for name=John
. When there is more than one John, I look for surname=Smith
. Now I don't care if there is more than one and I just take the first.