Last Updated : 11 Jul, 2025
The
Supplier Interfaceis a part of the
java.util.functionpackage which has been introduced since Java 8, to implement
functional programmingin Java. It represents a function which does not take in any argument but produces a value of type T. Hence this functional interface takes in only one generic namely:-
The lambda expression assigned to an object of Supplier type is used to define its
get()which eventually produces a value. Suppliers are useful when we don't need to supply any value and obtain a result at the same time. The Supplier interface consists of only one function:
1. get()This method does not take in any argument but produces a value of type T.
Syntax:T get()Returns:
This method returns a
valueof type T. Below is the code to illustrate get() method:
Program: Java
import java.util.function.Supplier;
public class Main {
public static void main(String args[])
{
// This function returns a random value.
Supplier<Double> randomValue = () -> Math.random();
// Print the random value using get()
System.out.println(randomValue.get());
}
}
Output:
0.5685808855697841
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4