Java8 instantiate a Predicate

San*_*Rey 0 java lambda functional-programming java-8

I am new in Java8, and I want to create a Predicate that checks if a value is contained inside a List of values, so I created:

public class Predicates {

    public static Predicate<String> isStringValueAllowed(List<String> allowedValues) {
        return allowedValues::contains;
    }
}
Run Code Online (Sandbox Code Playgroud)

and

String valueToCheck = "test";

        Predicate<String> predicate1 = (valueToCheck) -> Predicates.isStringValueAllowed(list);
Run Code Online (Sandbox Code Playgroud)

Era*_*ran 5

You are using the Predicate incorrectly.

To apply it to a String, you should call the Predicate's test() method, which returns a boolean:

boolean found = Predicates.isStringValueAllowed(list).test(valueToCheck);
Run Code Online (Sandbox Code Playgroud)