I am new in Java 8, and I want to get the first Phone that is not null from a list of contacts form a list of persons, but I am getting a incompatible types error
return segadors
                .stream()
                .map(c -> c.getSegadorMedium().stream().map(cm -> Objects.nonNull(cm.getPhoneSegador())))
                .findFirst()
                .orElse(null);
                  return segadors
            .stream()
            .flatMap(c -> c.getSegadorMedium().stream().filter(cm -> Objects.nonNull(cm.getPhoneSegador())))
            .findFirst()
            .orElse(null);
You need a filter in that Objects.nonNull check; plus since you are returning a Stream, you need a flatMap just before that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With