Using Java Predicate and Lambda

If you really are willing to get a boolean though from the Predicate, you can use its test method:

Predicate<String> nonEmptyStringPredicate = s -> !s.isEmpty();
boolean val = nonEmptyStringPredicate.test("any"); // true

Predicate on the other hand is just a FunctionalInterface, that you've represented using a lambda expression.


A Predicate gets in this case a String as parameter and returns a boolean. In case we don't write it as lambda it would look like this:

Predicate<String> somePredicate = new Predicate<String>() {
    @Override
    public boolean test(String string) {
        return !string.isEmpty();
    }
};