Java examples for Lambda Stream:Predicate
Use Predicate lambda
import java.util.function.Predicate; public class PredicateMain { public static void main(String[] args) { // We are passing a value to consumer and mention its behabiour print((a) -> a.startsWith("H"), "Hello"); print((a) -> a.startsWith("h"), "Hello"); print((a) -> a.length() >= 5, "Hello"); }/*from w w w .j a v a2s. c om*/ // Consumer consume value & return nothing public static void print(Predicate<String> predicate, String str) { if (predicate.test(str)) { System.out.println(str); } } }