IntConsumer Interface in Java with Examples Last Updated : 04 Aug, 2022 Comments Improve Suggest changes Like Article Like Report The IntConsumer Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which takes in one int-valued argument but does not return any value. The lambda expression assigned to an object of IntConsumer type is used to define its accept() which eventually applies the given operation on its only argument.It is similar to using an object of type Consumer<Integer> The IntConsumer interface consists of the following two functions: accept() This method accepts one value and performs the operation on its only argument. Syntax: void accept(int value) Parameters: This method takes in only one parameter: value- the input argument Returns: This method does not return any value. Below is the code to illustrate accept() method: Java import java.util.function.IntConsumer; public class GFG { public static void main(String args[]) { // Create a IntConsumer Instance IntConsumer display = a -> System.out.println(a * 10); // Using accept() method display.accept(3); } } Output:30andThen() It returns a composed IntConsumer wherein the parameterized IntConsumer will be executed after the first one. If the evaluation of either operation throws an error, it is relayed to the caller of the composed operation. Note: The operation being passed as the argument should be of type IntConsumer. Syntax: default IntConsumer andThen(IntConsumer after) Parameters: This method accepts a parameter after which is the IntConsumer to be applied after the current one. Return Value: This method returns a composed IntConsumer that first applies the current operation first and then the after operation. Exception: This method throws NullPointerException if the after operation is null. Below programs illustrate andThen() method: Program 1: Java import java.util.function.IntConsumer; public class GFG { public static void main(String args[]) { // Create a IntConsumer Instance IntConsumer display = a -> System.out.println(a * 10); IntConsumer mul = a -> a *= 10; // Using andThen() method IntConsumer composite = mul.andThen(display); composite.accept(3); } } Output:30 Program 2: To demonstrate when NullPointerException is returned. Java import java.util.function.IntConsumer; public class GFG { public static void main(String args[]) { try { // Create a IntConsumer Instance IntConsumer mul = a -> a *= 10; IntConsumer composite = mul.andThen(null); composite.accept(3); } catch (Exception e) { System.out.println("Exception : " + e); } } } Output:Exception : java.lang.NullPointerException Program 3: To demonstrate how an Exception in the after function is returned and handled. Java import java.util.function.IntConsumer; public class GFG { public static void main(String args[]) { try { // Create a IntConsumer Instance IntConsumer divide = a -> a = a / (a - 3); IntConsumer mul = a -> a *= 10; IntConsumer composite = mul.andThen(divide); composite.accept(3); } catch (Exception e) { System.out.println("Exception : " + e); } } } Output:Exception : java.lang.ArithmeticException: / by zero Comment More infoAdvertise with us Next Article IntConsumer Interface in Java with Examples P psil123 Follow Improve Article Tags : Misc Java Java - util package java-basics java-interfaces Java 8 Java-Functional Programming +3 More Practice Tags : JavaMisc Similar Reads IntFunction Interface in Java with Examples The IntFunction Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which takes in an int-valued argument and produces a result of type R. This functional interface takes in only one gener 1 min read Supplier Interface in Java with Examples The Supplier Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which does not take in any argument but produces a value of type T. Hence this functional interface takes in only one gener 1 min read Class isInterface() method in Java with Examples The isInterface() method of java.lang.Class class is used to check if this Class is an interface. The method returns true if this Class is an interface. It returns false otherwise. Syntax: public boolean isInterface() Parameter: This method does not accept any parameter. Return Value: This method re 2 min read Java.util.function.IntBinaryOperator interface with Examples The IntBinaryOperator interface was introduced in Java 8. It represents an operation on two int values and returns the result as an int value. It is a functional interface and thus can be used as a lambda expression or in a method reference. It is mostly used when the operation needs to be encapsula 2 min read SortedSet Interface in Java with Examples The SortedSet interface is present in java.util package extends the Set interface present in the collection framework. It is an interface that implements the mathematical set. This interface contains the methods inherited from the Set interface and adds a feature that stores all the elements in this 8 min read Map.Entry interface in Java with example Map.Entry interface in Java provides certain methods to access the entry in the Map. By gaining access to the entry of the Map we can easily manipulate them. Map.Entry is a generic and is defined in the java.util package. Declaration : Interface Map.Entry k -> Key V -> Value Methods: equals (O 4 min read Java 8 | IntSupplier Interface with Examples The IntSupplier Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which does not take any argument but produces an int value. The lambda expression assigned to an object of IntSupplier t 1 min read LongConsumer Interface in Java with Examples The LongConsumer Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which takes in one long-valued argument but does not return any value. The lambda expression assigned to an object of L 3 min read ToIntFunction Interface in Java with Examples The ToIntFunction Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which takes in an argument of type T and produces an int-valued result. This functional interface takes in only one ge 1 min read Java Native Interface with Example In the Programming World, it is often seen in the comparison of Java vs C/C++. Although the comparison doesn't make any such sense, as both the languages have their Pros and Cons, but what if we can use multiple languages in a single Program?In this article, we will learn How to use JNI(Java Native 4 min read Like