 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use IntSupplier in lambda expression in Java?
An IntSupplier is a functional interface defined in "java.util.function" package. This interface represents an operation that takes without arguments and returns the result of int type. IntSupplier interface has only one method, getAsInt() and returns a result. This functional interface can be used as an assignment target for lambda expressions or method references.
Syntax
@FunctionalInterface public interface IntSupplier {    int getAsInt(); }  Example
import java.util.function.IntSupplier; public class IntSupplierTest {    public static void main(String[] args) {       IntSupplier intSupplier1 = () -> Integer.MAX_VALUE;  // lamba expression       System.out.println("The maximum value of an Integer is: " + intSupplier1.getAsInt());       IntSupplier intSupplier2 = () -> Integer.MIN_VALUE;       System.out.println("The minimum value of an Integer is: " + intSupplier2.getAsInt());       int a = 10, b = 20;       IntSupplier intSupplier3 = () -> a*b;       System.out.println("The multiplication of a and b is: " + intSupplier3.getAsInt());    } } Output
The maximum value of an Integer is: 2147483647 The minimum value of an Integer is: -2147483648 The multiplication of a and b is: 200
Advertisements
 