Consumer Interface

The java.util.function.Consumer<T> interface has 1 abstract method accept

that takes object of generic type T and returns no result(void).

Usage:  You can use this Interface where you want to perform some operation on an object ,like we can create our own forEach method using Consumer Interface as I have shown below

Here I have given implementation of consumer using lambda and every call to accept method of consumer Interface will call this implementation and will print the below output

I have created this video to learn how to use consumer interface , you can watch this video as well

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *