- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- How to use BooleanSupplier in lambda expression in Java?
- How to use Supplier interface in lambda expression in Java?
- How to use BinaryOperator interface in lambda expression in Java?
- How to use UnaryOperator interface in lambda expression in Java?
- How to use Predicate and BiPredicate in lambda expression in Java?
- How to use FileFilter interface in lambda expression in Java?\n
- How to use a return statement in lambda expression in Java?
- How to use an ArrayList in lambda expression in Java?\n
- How to use Consumer and BiConsumer interfaces in lambda expression in Java?
- How to use Function and BiFunction interfaces in lambda expression in Java?
- How to use this and super keywords with lambda expression in Java?
- How to write a conditional expression in lambda expression in Java?
- How to use a final or effectively final variable in lambda expression in Java?
- Lambda expression in Java 8
- How to implement IntBinaryOperator using lambda expression in Java?

Advertisements