Java Lambda - LongPredicate and example








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

Syntax

and has the following syntax.

default LongPredicate and(LongPredicate other)

Example

The following example shows how to use and.

import java.util.function.LongPredicate;
/*w  w  w  .ja va  2  s  .c o  m*/
public class Main {

  public static void main(String[] args) {
    LongPredicate i = (l) -> l > 0;
    LongPredicate j = (l) -> l == 0;
    
    System.out.println(i.and(j).test(Long.MAX_VALUE));
  }
}

The code above generates the following result.