Java Stream How to - Use Predicate as function parameter








Question

We would like to know how to use Predicate as function parameter.

Answer

import java.util.function.Predicate;
public class Main {
    public static void main(String[] args) {
        boolean sonuc = checkVisaCode(s -> (s >= 400), 405);
/*ww  w  .  ja  v  a 2 s  .  c  o m*/
        System.out.println("Test result: " + sonuc);
    }

    public static boolean checkVisaCode(Predicate<Integer> pred, Integer param) {

        return pred.test(param);

    }
}

The code above generates the following result.