Skip to content
Related Articles

Related Articles

Supplier Interface in Java with Examples
  • Last Updated : 08 Oct, 2018

The Supplier Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in 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:-

  • T: denotes the type of the result

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.


T get()

Returns: This method returns a value of type T.

Below is the code to illustrate get() method:


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()

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :