beginnerFunctional Programming

What is the Function functional interface in Java, and when do you use it?

Function<T, R> represents a function that takes one argument of type T and returns a result of type R, via its single abstract method R apply(T t). It's the go-to interface for transformation logic — e.g. Function<String, Integer> length = String::length — and is what Stream.map() expects as its argument.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to You insert a mutable object as a HashMap key and later modify it. What can go wrong?← Back to all Core Java questions