Predicate and example

Description

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

Syntax

and has the following syntax.


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

Example

The following example shows how to use and.


import java.util.function.Predicate;
// w  w  w . j ava2  s  . co  m
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("java2s.com "));
  }
}

The code above generates the following result.