Getting first element and returning after apply a function
问题 I am new in Java 8, I want to make a method that gets the first element that matched and returning after apply a function public void test() { List<String> features = Arrays.asList("Lambdas", "Default Method", "Stream API", "Date and Time API"); String str = features .stream() .filter(s -> "Lambdas".equals(s)) .findFirst() .ifPresent(this::toLowerCase); } private String toLowerCase (String str) { return str.toLowerCase(); } but I got an Incompatible types error. 回答1: Optional.ifPresent