Java 8 IntSupplier Interface

7 years ago Lalit Bhagtani 0

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

Java 8 IntSupplier Interface

IntSupplier Interface :-

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

Abstract method :- 

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

Reference :-  IntSupplier Interface JavaDocs 

Example :- 

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

  public static void main(String[] args){
 
    IntSupplier intSupplier = ( ) -> { return 5; };
    System.out.println(intSupplier.getAsInt());
 
 }

Result :- 

5

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