Bi-Consumer interface What is Bi-Consumer interface ? Bi-Consumer interface is one of the functional interfaces that Java 8 provides. It is present in java.util.function package. It is quite similar to consumer interface, just that it accepts two parameters. @FunctionalInterface public interface BiConsumer<T,U> Since it is a functional interface it has only one method definition . That method is called Accept. We all know functional interfaces can have default methods also . So here we have a default method called andThen . What are the methods of the Bi-Consumer interface ? Accept : void accept(T t,U u) The accept method accepts two input parameter and performs a user defined operation on them. AndThen : default BiConsumer<T,U> andThen(BiConsumer<? super T,? super U> after) The andThen method takes in a Bi-Consumer as an input and it runs it after the Bi-Consumer it is called upon. Let us look at few examples !!!!!! First lets look at the example
Consumer Interface What is consumer interface ? Consumer interface is one of the functional interfaces that Java 8 provides. It is present in java.util.function package. @FunctionalInterface public interface consumer<T> Let us look at some of the important points about the consumer interface below. Consumer interface is a functional interface that is it only has on method definition and that method is called the accept . It takes in only one parameter and does not return anything as the output. public void accept(T t) We also know that functional interfaces can have method of default scope also that is default methods. Well Consumer interface also has one default method know as andThen which takes in a consumer as input parameter. default Consumer<T> andThen(Cosumer<? super T> after) This method is used to link the consumers together . That is to make one consumer run after other. Let us look at few exam