What is Consumer and BiConsumer in Java? Consumer in Java Consumer is Functional Interface which takes arguments only and return nothing. Consumer is Interface in Java Programming language which introduced in Java 8 and it is part of java.util.function. As a name suggest, it only consumes not return anything. means it consumes value and perform required operations. @FunctionalInterface public interface Consumer<T> { void accept(T t); } Consumer only contains two methods : one is abstract and another is default. void accept (T t) default Consumer<T> andThen(Consumer<? super T> after) You can see return type of accept method is void means it does not return anything. Consumer can be used in all contexts where an object needs to be consumed, Like taken as input, and some operation is to be performed on the object without returning any result. Since Consumer is a functional interface, hence it can be used as the assignment target for a lambda expression or a...
Welcome To Programming Tutorial. Here i share about Java Programming stuff. I share Java stuff with simple examples.