Lambda: currying turns a two-argument function into nested one-argument functions

Currying reshapes a function of two arguments into a function that takes the first argument and returns a new function waiting for the second, which lets one argument be fixed early and reused.

Code
Function<Integer, Function<Integer, Integer>> add = a -> b -> a + b;
Function<Integer, Integer> add10 = add.apply(10);
System.out.println("add10 applied to 5: " + add10.apply(5));
System.out.println("add10 applied to 7: " + add10.apply(7));
System.out.println("direct add(2)(3): " + add.apply(2).apply(3));
Output
add10 applied to 5: 15
add10 applied to 7: 17
direct add(2)(3): 5
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms