Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator
functional
intfunction

What is the IntFunction functional interface in Java?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

IntFunction is a functional interface in Java that accepts one argument of type int and returns a result R. The interface contains one method, i.e., apply.

The IntFunction interface is defined in the java.util.function package. To import the IntFunction interface, check the following import statement.

import java.util.function.IntFunction;

Method

The apply(int value) method applies the function to the given argument of type int. This is the functional method of the interface.

Syntax

R apply(int value);

Parameter

  • int value: The function argument of type int.

Returns

  • R: The method returns the function result.

Code

import java.util.function.IntFunction;
public class Main{
public static void main(String[] args) {
IntFunction<String> stringIntFunction = (d) -> String.format("The passed value is %s", d);
int i = 100;
// calling apply method of the IntFunction
System.out.println(stringIntFunction.apply(i));
}
}

In the above code, we created an implementation of the IntFunction interface that accepts an int argument and returns a string.

RELATED TAGS

java
communitycreator
functional
intfunction

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring