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.

Method

  1. DoubleConsumer accept
  2. DoubleConsumer andThen




Example

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);
    d.accept(0.23);
  }
}

The code above generates the following result.