Java Lambda - BooleanSupplier example








BooleanSupplier represents a supplier of boolean-valued results.

Method

  1. BooleanSupplier getAsBoolean

Example

The following example shows how to use BooleanSupplier.

import java.util.function.BooleanSupplier;
// ww  w  .ja  v  a 2s . c o m
public class Main {
  public static void main(String[] args) {
    BooleanSupplier bs = () -> true;
    System.out.println(bs.getAsBoolean());

    int x = 0, y= 1;
    bs = () -> x > y;
    System.out.println(bs.getAsBoolean());
  }
}

The code above generates the following result.