Java 8 BooleanSupplier Interface

7 months ago codedestine 0

In this tutorial, we will learn about Java 8 BooleanSupplier interface.

Java 8 BooleanSupplier Interface

BooleanSupplier Interface :-

BooleanSupplier ( java.util.function.BooleanSupplier ) is a functional interface that has one abstract method declared in it. This interface is boolean producing primitive specialised form of Supplier interface.

Abstract method :- 

boolean  getAsBoolean (  ) :- The abstract method getAsBoolean (  ) is a functional method. It does not accept any argument but return newly generated boolean values in the stream. It represents an operation by which you can generate new boolean values in the stream.

Reference :-  BooleanSupplier Interface JavaDocs

Example :- 

This example will show you, how to create and call different methods of a BooleanSupplier interface.

  public static void main(String[] args){
 
    BooleanSupplier booleanSupplier = ( ) -> { return true; };
    System.out.println(booleanSupplier.getAsBoolean()); 
 
  }

Result :- 

true 

That’s all for Java 8 BooleanSupplier Interface. If you liked it, please share your thoughts in comments section and share it with others too.