个人技术分享

BiConsumer class

The BiConsumer interface is a part of the Java 8's functional interface package (java.util.function). It represents an operation that accepts two input arguments and returns no result.

Here's its definition:

@FunctionalInterface
public interface BiConsumer<T, U> {
    void accept(T t, U u);
}

It has a single method accept that takes two arguments T and U and performs some operation without returning any result. It's similar to the Consumer interface, but it takes two arguments instead of one.

Here's an example of how you can use BiConsumer:

import java.util.function.BiConsumer;

public class BiConsumerExample {
    public static void main(String[] args) {
        BiConsumer<String, Integer> biConsumer = (str, num) -> System.out.println(str + num);
        biConsumer.accept("Number is: ", 10);
    }
}

In this example, the BiConsumer takes a String and an Integer and prints them together.