Predicate for List processing - Java Lambda Stream

Java examples for Lambda Stream:Predicate

Description

Predicate for List processing

Demo Code



import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class PredicateDemo2 {
  public static void main(String args[]) {
    List<String> list = Arrays.asList("aman", "varun", "Jarnail", "Samita", "Sonam");
    Predicate<String> predicate = n -> n.length() > 5 ? true : false;
    eval(list, predicate);//from   w  w  w  .  j a v  a  2  s . co m
    eval(list, n -> n.length() > 5 ? true : false);
  }

  public static void eval(List<String> list, Predicate<String> predicate) {
    for (String n : list) {

      if (predicate.test(n)) {
        System.out.println(n + " ");
      }
    }
  }
}

Related Tutorials