One usage of Function is in Streams. Everyone uses map method these days, I believe:

This map method accepts the Function as a parameter. This allows writing a pretty elegant code - something that could not be achieved before Java 8:

Stream.of("a", "b", "c")
   .map(s -> s.toUpperCase())
   .collect(Collectors.toList());
// List of A, B, C

Now its true that there are method references and functional interfaces (one of which is Function of course), this lets you using method reference to rewrite the above example as:

Stream.of("a", "b", "c")
    .map(String::toUpperCase)
    .collect(Collectors.toList())

... but that's only a syntactic sugar - map still accepts the Function as a parameter of course.

Another example that uses Function from Java itself is StackWalker: Here is an example:

List<StackFrame> frames = StackWalker.getInstance().walk(s ->
    s.dropWhile(f -> f.getClassName().startsWith("com.foo."))
     .limit(10)
     .collect(Collectors.toList()));
}

Note the call to walk method - it accepts a function as a parameter.

So bottom line, it's just yet another tool that can help the programmer to express his/her intentions. Use it wisely wherever appropriate.

Answer from Mark Bramnik on Stack Overflow
🌐
Mkyong
mkyong.com › home › java8 › java 8 function examples
Java 8 Function Examples - Mkyong.com
February 27, 2020 - package com.mkyong; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; public class Java8Function3 { public static void main(String[] args) { Java8Function3 obj = new Java8Function3(); List<String> list = Arrays.asList("node", "c++", "java", "javascript"); // lambda Map<String, Integer> map = obj.convertListToMap(list, x -> x.length()); System.out.println(map); // {node=4, c++=3, java=4, javascript=10} // method reference Map<String, Integer> map2 = obj.convertListToMap(list, obj::getLength); System.out.println(ma
🌐
W3Schools
w3schools.com › java › java_methods.asp
Java Methods
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions...
🌐
GeeksforGeeks
geeksforgeeks.org › java › function-interface-in-java
Function Interface in Java - GeeksforGeeks
July 11, 2025 - Return Type: This method returns the function result, which is of type R. Example: Java ·
🌐
Dremendo
dremendo.com › java-programming-tutorial › java-function
Function in Java Programming | Dremendo
In Pass by Value the values of the variables are passed to the formal arguments of the function. In this case the values of the actual arguments are not affected by changing the values of the formal arguments. See the example given below. import java.util.Scanner; public class Example { public static void changevalue(int a,int b) { a=a+2; b=b+2; System.out.println("In function changes are " + a + " and " + b); } public static void main(String args[]) { int x=10,y=20; System.out.println("Before calling the function"); System.out.println("x=" + x + " and y=" + y); changevalue(x,y); System.out.println("After calling the function"); System.out.println("x=" + x + " and y=" + y); } }
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Get-the-most-from-Java-Function-interface-with-this-example
A simple Java Function interface example: Learn Functional programming fast
For this Java Function interface example, we will provide a single method named “apply” that takes an Integer as an argument, squares it and returns the result as a String.
🌐
Learn Java
learnjavaonline.org › en › Functions
Functions - Learn Java - Free Interactive Java Tutorial
I always like to say that arguments to Java methods are passed by value, although some might disagree with my choice of words, I find it the best way to explain and understand how it works exactly. By value means that arguments are copied when the method runs. Let's look at an example.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › function › Function.html
Function (Java Platform SE 8 )
3 weeks ago - Returns a function that always returns its input argument. ... Java™ Platform Standard Ed. 8 ... Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples...
Find elsewhere
🌐
Programiz
programiz.com › java-programming › methods
Java Methods (With Examples)
August 26, 2024 - In the above example, we have created a method named addNumbers(). The method takes two parameters a and b. Notice the line, ... Here, we have called the method by passing two arguments num1 and num2. Since the method is returning some value, we have stored the value in the result variable. Note: The method is not static. Hence, we are calling the method using the object of the class. A Java method may or may not return a value to the function ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › methods-in-java
Java Methods - GeeksforGeeks
All methods in Java must belong to a class. Methods are similar to functions and expose the behavior of objects. A method allows to write a piece of logic once and reuse it wherever needed in the program. This helps keep your code clean, organized, easier to understand and manage. ... public class Geeks { // An example method public void printMessage() { System.out.println("Hello, Geeks!"); } public static void main(String[] args) { // Create an instance of the class // containing the method Geeks obj = new Geeks(); // Calling the method obj.printMessage(); } }
Published   3 weeks ago
🌐
Javabrahman
javabrahman.com › java-8 › java-8-java-util-function-function-tutorial-with-examples
Java 8 java.util.function.Function Tutorial with Examples
Lets see the example below which uses the same funcEmpToString Function as used in the apply() usage example and combines it with a funcEmpFirstName Function instance which converts the full-name of the employee object passed to it to just the first name of the employee - Java 8 code showing usage of default method Function.compose()
🌐
DZone
dzone.com › coding › java › functional programming with java 8 functions
Functional Programming with Java 8 Functions
October 20, 2014 - This is a classical example of what is called function composition. In some languages there is even a binary operator to compose two functions in this way: ... Where o would be an operator that would compose functions f and g pretty much as we did in pseudocode above and produce a new function h. ... I can think of two ways to do this in Java...
🌐
Tutorialspoint
tutorialspoint.com › java › java_methods.htm
Java - Methods
A Java method is a collection of statements that are grouped together to perform an operation. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console.
🌐
Vaia
vaia.com › java function
Java Function: Definition & Examples | Vaia
December 13, 2024 - A String is a sequence of characters, which in Java is represented by the String class. It is immutable, meaning its value cannot be changed once created. ... split(String regex): Splits string into an array based on a regular expression.These functions help in effectively managing and manipulating string data. Consider an example demonstrating several string methods:
🌐
Medium
medium.com › javaguides › java-function-functional-interface-with-real-world-examples-a1e86ea0fda5
Java Function Functional Interface with Real-World Examples | by Ramesh Fadatare | JavaGuides | Medium
March 1, 2025 - Learn how to use Java’s Function functional interface with a real-world example. Explore apply(), andThen(), compose(), and identity()…
🌐
freeCodeCamp
freecodecamp.org › news › functional-programming-in-java
Functional Programming in Java
January 20, 2026 - This article explores how to implement FP concepts in Java, including viewing functions as first-class citizens, chaining, and composing them to create function pipelines. We'll also discuss the technique of currying, which allows a function that takes multiple arguments to be transformed into a chain of functions that each take a single argument. This can simplify the use of complex functions and make them more reusable. In this article, I'll show you examples of how to implement these concepts in Java using modern language features, like “java.util.function.Function”, “java.util.function.BiFunction”, and a user-defined TriFunction.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › main-Java-function-example-class-call
Java's main function explained with examples
April 29, 2021 - Instances can only be created after a Java application has started. If the main method was not static, it would require code to have already run in order for it to be invoked. The static keyword on the main method allows this function to be used as the entry point for an application, before any other Java code has run, and before any Java instances have been created.
🌐
Medium
medium.com › @AlexanderObregon › methods-vs-functions-in-java-for-beginners-0a22c5893aef
Methods vs Functions in Java for Beginners | Medium
December 8, 2024 - This association with a class is what sets methods apart from standalone functions. Methods are an integral part of Java’s object-oriented programming structure. ... Association with Classes or Objects: A method must belong to a class in Java. It cannot exist on its own. Object-Oriented Behavior: Methods allow objects to encapsulate behaviors alongside data. For example, a Car object might have methods like start() or stop() to define what actions the car can perform.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › function › Function.html
Function (Java SE 17 & JDK 17)
October 20, 2025 - Package java.util.function · Type Parameters: T - the type of the input to the function · R - the type of the result of the function · All Known Subinterfaces: UnaryOperator<T> Functional Interface: This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.