'Usage of BiConsumer interface in java 8

I'm new to programming with streams and functional interfaces and the java.util.function.BiConsumer describes the method accept like below in the documentation which is not clear to understand

void accept(T t,
            U u)
Performs this operation on the given arguments.
Parameters:
t - the first input argument
u - the second input argument

Functional interfaces can be referred using the lamda expressions like below

BiConsumer<String,String> a=(a,b)->{
 
}

But what does the "this operation mean here exactly". Thanks in advance



Solution 1:[1]

But what does the "this operation" mean here exactly?

The BiConsumer interface is effectively a signature for any function that takes two arguments of two reference types (or in your example, the same type) and returns nothing. A function that conforms to this interface could do anything with them. It could print them. It could add them to some map. It could ... throw them away, and do absolutely nothing.

The "this operation" refers to the lambda that (in effect) implements the interface. Or more precisely, what the lambda does.

So ... basically ... when you pass (say) a lambda as an argument of type BiConsumer to some method, that method can call accept(arg1, arg2) and expect that it will do what that javadoc says; i.e. apply "the operation" implemented by the lambda (or whatever) to those two arguments.

Now the BiConsumer interface is a bit unusual because it doesn't return anything. So it is not as widely used as other functional interfaces. But if you are looking for examples, try this:

Solution 2:[2]

To add on top of above scenario mentioned,there is one more in-built usage of BiConsumer:

ForEach default method of map

which got introduced in Java-8

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 facebook-100001358991487