Higher Order Function. Get hold of all the important DSA concepts with the What is java.util.function.Consumer. If evaluation of either function throws an error, it is relayed to the caller of the composed operation.Attention reader! super T> after) Returns a composed Consumer that performs, in sequence, this operation followed by the after operation. The Consumer Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. default Consumer andThen(Consumer
2.1 This example accepts Consumer as an argument, simulates a forEach to print each item from a list. taken as input, and some operation is to be performed on the object without returning any result. Don’t stop learning now. The following examples show how to use java.util.function.Consumer.These examples are extracted from open source projects. If performing either operation throws an exception, it is relayed to the caller of the composed operation. Please write to us at contribute@geeksforgeeks.org to report any issue with the above content. Package java.util.function Description Functional interfaces provide target types for lambda … It represents a function which takes in one argument and produces a result. acknowledge that you have read and understood our import java.util.function.Consumer; public class Main { public static void main (String [] args) { Consumer c = (x) -> System.out.println (x.toLowerCase ()); c.accept ( "Java2s.com" ); } } The code above generates the following result. Since Consumer is a functional interface, hence it can be used as the assignment target for a lambda expression or a method reference.Code showing usage of default method Consumer.andThen() 1(printed  1)  10(printed  10)  200(printed  200)  101(printed  101)  -10(printed  -10)  0(printed  0)Tutorial explains the in-built functional interface Advantage of predefined java.util.function.ConsumerClick to Read Detailed Tutorial on Default Methods in Java 8 1(printed  1)  10(printed  10)  200(printed  200)  101(printed  101)  -10(printed  -10)  0(printed  0)Tutorial on basics of Functional Interfaces in Java 8Click to read tutorial on Predicate Functional InterfaceClick to read tutorial on Consumer Functional InterfaceClick to read tutorial on Supplier Functional InterfaceClick to read overview of java.util.function packageCopyright © 2014-2020 JavaBrahman.com, all rights reserved. Consumer is an in-built functional interface introduced in Java 8 in the java.util.function package. Consumer can be used in all contexts where an object needs to be consumed,i.e. However these kind of functions don’t return any value. 2.