Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator
functional
tointfunction

What is the ToIntFunction 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.

ToIntFunction is a functional interface that accepts one argument and returns an int type result. The interface contains one method, i.e., applyAsInt.

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

import java.util.function.ToIntFunction;

applyAsInt(T value)

This method applies the function to the given argument and returns the int type result. This is the functional method of the interface.

Syntax

int applyAsInt(T value);

Parameters

  • T value: This is the function argument.

Returns

The method returns the result of type int.

Code

import java.util.function.ToIntFunction;
public class Main{
public static void main(String[] args) {
ToIntFunction<Integer> convertSumToInt = (i1) -> i1 + 5;
Integer i1 = 5;
// calling applyAsInt method of the ToIntFunction
System.out.println(convertSumToInt.applyAsInt(i1));
}
}
applyAsInt() method example

RELATED TAGS

java
communitycreator
functional
tointfunction

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