Java Lambda - Predicate and example

Predicate and returns a composed predicate that represents a short-circuiting logical AND of this predicate and another.


and has the following syntax.

default Predicate<T> and(Predicate<? super T> other)


The following example shows how to use and.

import java.util.function.Predicate;
//from  w  w  w  . j a v  a 2  s  .c  om
public class Main {

  public static void main(String[] args) {
    Predicate<String> i  = (s)-> s.length() > 5;
    Predicate<String> j  = (s)-> s.length() < 3;
    System.out.println(i.and(j).test(" "));

The code above generates the following result.