The ObjDoubleConsumer 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 takes in two arguments and produces a result. However these kind of functions don't return any value.
Hence this functional interface takes in one generic namely:-
Java
- T: denotes the type of the input argument to the operation
Functions in ObjDoubleConsumer Interface
The ObjDoubleConsumer interface consists of the following two functions:1. accept()
This method accepts two values and performs the operation on the given arguments. Syntax:void accept(T t, double value)Parameters: This method takes in two parameters:
- t- the first input argument
- value- the second input argument
// Java code to demonstrate
// accept() method of ObjDoubleConsumer Interface
import java.util.Arrays;
import java.util.List;
import java.util.function.ObjDoubleConsumer;
import java.util.stream.Stream;
public class GFG {
public static void main(String args[])
{
// Get the list from which
// the Interface is to be instantiated.
List<Integer>
arr = Arrays.asList(3, 2, 5, 7, 4);
// Instantiate the ObjDoubleConsumer interface
ObjDoubleConsumer<List<Integer> >
func = (list, num) ->
{
list.stream()
.forEach(
a -> System.out.println(a * num));
};
func.accept(arr, 2.0);
}
}
Output:
6.0 4.0 10.0 14.0 8.0