Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Java 8 | DoubleSupplier Interface with Examples

  • Last Updated : 10 Oct, 2018

The DoubleSupplier 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 double value.

The lambda expression assigned to an object of DoubleSupplier type is used to define its getAsDouble() which eventually applies the given operation on its argument. It is similar to using an object of type Supplier<Double>

Functions in DoubleSupplier Interface

The DoubleSupplier interface consists of the only one function:

1. getAsDouble()

This method does not take in any value but produces a double-valued result.


double getAsDouble()

Return Value: This method returns a double value.

Below is the code to illustrate getAsDouble() method:


// Java Program to illustrate
// getAsDouble method of
// DoubleSupplier Interface
import java.util.function.DoubleSupplier;
public class GFG {
    public static void main(String args[])
        // Create a DoubleSupplier instance
        DoubleSupplier sup = () -> Math.random();
        // Get the double value
        // Using getAsDouble() method

My Personal Notes arrow_drop_up

Start Your Coding Journey Now!