Java Lambda - DoubleConsumer example

DoubleConsumer functional interface represents an operation that accepts a single double-valued argument and returns no result. This is the primitive type specialization of Consumer for double.


  1. DoubleConsumer accept
  2. DoubleConsumer andThen


The following example shows how to use DoubleConsumer.

import java.util.function.DoubleConsumer;

public class Main {
  public static void main(String[] args) {
    DoubleConsumer d = (x) -> System.out.println(x*x);

The code above generates the following result.