A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/java-8-objlongconsumer-interface-with-example/ below:

Java 8 | ObjLongConsumer Interface with Example

Java 8 | ObjLongConsumer Interface with Example

Last Updated : 11 Jul, 2025

The

ObjLongConsumer 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 two arguments and produces a result. However these kind of functions don't return any value. Hence this functional interface takes in one generic namely:-

The lambda expression assigned to an object of ObjLongConsumer type is used to define its

accept()

which eventually applies the given operation on its argument. It takes in a long-valued and a T-valued argument and is expected to operate without any side effects. It is more like using an object of type

BiConsumer

<T, Long> except the fact that one is a reference and one is a primitive data type in this case. Hence we will be obtaining one reference and one value when this function is called.

Functions in ObjLongConsumer Interface

The ObjLongConsumer interface consists of the following two functions:

1. accept()

This method accepts two values and performs the operation on the given arguments.

Syntax:
void accept(T t, long value)
Parameters:

This method takes in two parameters:

Return Value:

This method does not return any value. Below is the code to illustrate accept() method:

Program: Java
// Java code to demonstrate
// accept() method of ObjLongConsumer Interface

import java.util.Arrays;
import java.util.List;
import java.util.function.ObjLongConsumer;
import java.util.stream.Stream;

public class GFG {
    public static void main(String args[])
    {

        // Get the list from which
        // the Interface is to be instantiated.
        List<Integer>
            arr = Arrays.asList(3, 2, 5, 7, 4);

        // Instantiate the ObjLongConsumer interface
        ObjLongConsumer<List<Integer> >
            func = (list, num) ->
        {
            list.stream()
                .forEach(
                    a -> System.out.println(a * num));
        };
        func.accept(arr, 200000);
    }
}
Output:
600000
400000
1000000
1400000
800000


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4