BiFunction Java 812 May 2025 | 3 min read In Java, BiFunction is a functional interface. It was introduced in Java 8. It can be used as an assignment target for a lambda expression or method reference. It belongs to java.util.function package. The interface accepts three type-parameters are as follows: T: It denotes the first argument to the function. U: It denotes the second argument to the function. R: It denotes the result of the function. T, U, and R are the descriptor that can be represented as (T, U)->R. BiFunction Interface MethodsThe interface has the following two methods:
BiFunction apply() MethodThe apply() method performs the operation on the given arguments and returns the function result. Syntax: Parameters: t: It represents the first function argument. u: It represents the second function argument. Returns: It returns the function result. ExampleBiFunctionApplyExample.java Output: The sum of x and y is: 35 BiFunction andThen() MethodIt returns a composed function. It means the method first applies this function and then applies the after function. If the assessment of either function throws an exception, it is relayed to the caller of the composed function. Syntax: Type-Parameter: V: It represents the type of the output of the after() function, and of the composed function. Parameters: after: It applies after this function. Returns: It returns a composed function. It means the method first applies this function and then applies the after function. The method throws a NullPointerException if after is null. ExampleBiFunctionAndThenExample.java Output: The result is: 350 Let's implement the above two methods in a Java program and understand the working of BiFunction interface. BiFinction ExampleBiFunctionExample1.java Output: 46 576 In the above program, the statement System.out.println(f1.andThen(f2).apply(2, 3)); can be written as follows: Integer r1 = f1.apply(11, 13); Integer r2 = f2.apply(r1); System.out.println(r2); //returns and print 576 Let's see another example. BiFunctionExample2.java Output: [Key=1, Olivia(1)] [Key=2, Noah(2)] [Key=3, John(1)] [Key=4, Alex(1)] [Key=5, Emma(1)] [Key=6, Amelia(1)] [Key=7, Noah(2)] |
Java Assignment Operators with Examples
The fundamental building block of each programming language is an operator. Additionally, Java has a wide variety of operators that can be used for arithmetic, relational, logical, and other calculations and tasks. They are categorized according to the functions they provide. Assignment Operators: These operators can be used...
5 min read
Java Binary to Hexadecimal Conversion
In programming, converting one type to/ from a type is a crucial task. Sometimes we require, conversion from one type to another type. In the Java conversion section, we have discoed various types of conversions. In this section, we can discuss how to convert binary to...
5 min read
Check Whether a Number is a Power of 4 or not in Java
There are many ways to check whether a number is a power of 4 or not. In this section, we will discuss the different approaches to check whether a number is a power of 4 or not. Examples: Input: num = 7 Output: 7 is not the power of...
9 min read
Web Methods in Java
In the world of web development, Java remains a powerhouse due to its versatility, robustness, and platform independence. When building web applications, Java developers often use web methods to handle HTTP requests and responses. These web methods are the backbone of RESTful web services and play...
4 min read
StrictMath scalb() Method in Java
The value of a floating-point number multiplied by a power of two can be quickly and effectively calculated in Java using the StrictMath.scalb() function. Part of the java.lang.StrictMath class, this method yields more consistent results on various platforms than the java.lang.Math class since it contains a...
5 min read
Null Object Design Pattern Java
The Null Object Design Pattern is a behavioral design pattern that uses polymorphism to remove the need for null checks throughout your code. Instead of using null references to represent the absence of an object, we provide a default "null" object that exhibits the desired...
7 min read
Java IP Address (IPv4) Regex Examples
IP address are the unique numerical identifiers of each devices connected to a network. The first version of the IP addresses is a 32-bit address separated by period (.). In Java, Regex or Regular Expression is an API that defines the string patterns. It is widely used...
3 min read
How to Use Eclipse for Java
Eclipse is the most popular IDE for Java application development. In order to use eclipse effectively, we must familiar with the workbench, concepts, and components of Eclipse IDE. Before moving ahead in this section, we will understand what is eclipse in Java, eclipse platform overview, and...
5 min read
Cannot Find Symbol Error in Java
In Java programming, the "cannot find symbol" error means that the compiler can't recognize a specific identifier, like a variable or method name, used in your code. The error arises when you attempt to use a variable, method, class, or other identifier that hasn't been correctly...
10 min read
Dangling Else Problem in Java
The dangling else problem is an ambiguity of language interpretation. In programming, we can write conditionally executed code in the following two forms: if-then form if-then-else form The problem rarely occurs while we deal with the nested if-else statement. It is an ambiguity in which it is not clear...
2 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India