ObjLongConsumer Interface is a part of the java.util.function package which is introduced in Java 8. It is an in-built Functional Interface. This function expects an object-valued and a long-valued argument as input but produces no output. In this post, we are going to see several implementations of ObjLongConsumer Interface by using different examples.
ObjLongConsumer Interface in Java 8 with Examples...!!! Click To Tweet
Look at ObjLongConsumer Javadoc description below:
ObjLongConsumer Interface contains following method:
accept
Let’s discuss this method:
accept
This method performs operation on the given argument and return no result.
1 | void accept(T t, long value); |
Below is an example to demonstrate accept() method:
Example 1. with Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import java.util.function.ObjLongConsumer; public class ObjLongConsumerInterfaceJava8Example1 { public static void main(String args[]) { System.out.println("Ex. 1 - ObjLongConsumer - Integer example \n"); ObjLongConsumer <Integer> objLongConsumberObj = (t, value) -> System.out.println(t * value); objLongConsumberObj.accept(5, 10 L); } } |
Example 2. with String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.util.function.ObjLongConsumer; public class ObjLongConsumerInterfaceJava8Example2 { public static void main(String args[]) { System.out.println("Ex. 2 - ObjLongConsumer - String example \n"); ObjLongConsumer <String> ObjLongConsumberObj = (t, value) -> { if (t.length() > value) { System.out.println("String is bigger than the expected value."); } else if (t.length() == value) { System.out.println("String lenght is equal to expected value."); } else { System.out.println("String is shorter than the expected value."); } }; ObjLongConsumberObj.accept("justanordinarywriter.com", 15 L); ObjLongConsumberObj.accept("techndeck.com", (long) 15); } } |
ObjLongConsumer Interface in Java 8 with Examples...!!! Click To Tweet
Do you like this Post? – then check my other helpful posts:
- Passing Function as a Parameter in another Method in Java 8
- Collection sorting using Lambda in Java 8
- Generate Prime numbers in Java 8