Java BiConsumer Example

BiConsumer is a functional interface which represents an operation that accepts two input arguments and returns no result. This is the two-arity specialization of Consumer. Unlike most other functional interfaces, BiConsumer is expected to operate via side-effects.

Java BiFunction Example

Create a Person class:
public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        super(); = name;
        this.age = age;

    public String getName() {
        return name;

    public void setName(String name) { = name;

    public int getAge() {
        return age;

    public void setAge(int age) {
        this.age = age;
Here is an example of a BiConsumer interface:
public class BiConsumersExample {

    public static void main(String[] args) {
        BiConsumer<Person, Person> biConsumer = (p1, p2) -> {
             System.out.println(" print first person");
             System.out.println(" print second person");
       biConsumer.accept(new Person("Ramesh", 10), new Person("ram", 10));
 print first person
 print second person


Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course