Java 8 — Consumer | Code Factory

Index Page : Link

Reference Link : Link

Donate : Link

Sometimes our requirment is we have to provide some input value, perform certain operation, but not required to return anything, then we should go for Consumer .i.e Consumer can be used to consume object and perform certain operation.

Consumer Functional Interface contains one abstract method accept.

Output :

Program to display Movie Information by using Consumer :

Output :

Program to display Student Information by using Predicate, Function and Consumer :

Output :

Consumer Chaining :

Just like Predicate Chaining and Function Chaining, Consumer Chaining is also possible. For this Consumer Functional Interface contains default method andThen().


First Consumer c1 will be applied followed by c2 and c3.

Output :



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store