
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
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