Java Stream How to - Create Predicate to test Integer value








Question

We would like to know how to create Predicate to test Integer value.

Answer

//w  w w . j  a  va 2 s  .  c  om
import java.util.function.Predicate;

public class Main {
  public static void main(String[] args) {
    boolean sonuc = checkVisaCode(s -> (s >= 400), 405);

    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.