Java Lambda - Predicate or example








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

Syntax

or has the following syntax.

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

Example

The following example shows how to use or.

import java.util.function.Predicate;
// www .  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.or(j).test("java2s.com "));
  }
}

The code above generates the following result.