The solution depends on the answer to the question - are all the parameters going to be the same type and if so will each be treated the same?

If the parameters are not the same type or more importantly are not going to be treated the same then you should use method overloading:

public class MyClass
{
  public void doSomething(int i) 
  {
    ...
  }

  public void doSomething(int i, String s) 
  {
    ...
  }

  public void doSomething(int i, String s, boolean b) 
  {
    ...
  }
}

If however each parameter is the same type and will be treated in the same way then you can use the variable args feature in Java:

public MyClass 
{
  public void doSomething(int... integers)
  {
    for (int i : integers) 
    {
      ...
    }
  }
}

Obviously when using variable args you can access each arg by its index but I would advise against this as in most cases it hints at a problem in your design. Likewise, if you find yourself doing type checks as you iterate over the arguments then your design needs a review.

Answer from Nick Holt on Stack Overflow
🌐
Medium
medium.com › codex › multi-arity-functions-in-java-7bd71350e6cd
Multi-arity functions in Java. In Java 8, functions were introduced… | by Dr. Viktor Sirotin | CodeX | Medium
October 13, 2023 - Let me remind you: arity is the number of parameters of a function. Accordingly, multi-arity functions are functions with several parameters. In Java 8, functions were introduced with one and two input parameters.
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 133321 › how-methods-with-multiple-parameters-are-declared
java - How methods with multiple parameters are ... | DaniWeb
Methods with multiple parameters are defined by listing typed parameters in order; that list is part of the method’s signature along with the name and return type. Inside the method, those parameter names are local; the caller’s variable ...
🌐
W3Schools
w3schools.com › java › java_methods_param.asp
Java Method Parameters
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 ... Information can be passed to methods as a parameter.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › function › BiFunction.html
BiFunction (Java Platform SE 8 )
3 weeks ago - Returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function. ... Java™ Platform Standard Ed.
🌐
Baeldung
baeldung.com › home › java › core java › best practices for passing many arguments to a method in java
Best Practices for Passing Many Arguments to a Method in Java | Baeldung
June 6, 2025 - This article discusses the challenges of passing many arguments to a method in Java. It presents two design patterns to mitigate these issues: the Parameter Object Pattern and the Java Bean Pattern.
🌐
LabEx
labex.io › tutorials › java-how-to-define-a-method-with-multiple-parameters-in-java-414992
How to define a method with multiple parameters in Java | LabEx
By understanding the concept of ... Java, you can define methods that accept multiple parameters, allowing you to pass in more than one input value to the method....
Find elsewhere
Top answer
1 of 3
40
Function<Integer,Integer,Integer> f3 = (x,y) -> {return x + y};

is actually a BiFunction<Integer,Integer,Integer>

and

Function<Double> f4 = () -> {return Math.random()};

is a Supplier<Double>

If you need more create your own, like TriFunction<Integer,Integer,Integer,Integer> for example

2 of 3
8

I am almost sure that you can define own functional interface (i.e., create a new file commonly) to develop f3 and f4, but Is there some way to easily define them?

In addition to the Eugene answer, I would add that :

Function<Integer,Integer,Integer> f3 = (x,y) -> {return x + y};

may be considered as BiFunction<Integer,Integer,Integer> or simply BinaryOperator<Integer>. Note that you perform arithmetical computations with the Integers in the lambda body. These produce unboxing and boxing operations : Integer->int->Integer. So in this use case you are encouraged to use a specialized functional interface that prevents that : IntBinaryOperator which the functional signature is (int, int)-> int that is itself a specialization of BinaryOperator<T> a subclass of BiFunction<T,T,T>

In the same logic of sparing autoboxing operations : Function<Integer,Integer> f2 should be IntFunction f2 and Supplier<Double> f4 should be DoubleSupplier f4.

Note also that specifying a specific number of argument makes sense as it is straight usable in a lambda body but specifying something like a var-args is possible but generally harder to exploit.

For example you could declare this interface :

@FunctionalInterface
public interface VargsFunction<T,R> {
    @SuppressWarnings("unchecked")
    R apply(T...  t);
}

But harder to use without delegating to a method that accepts a var-args :

VargsFunction<Integer, Integer> f = varg-> call(varg);

Integer call(Integer... varg) {
    ...
}
🌐
TutorialsPoint
tutorialspoint.com › how-many-parameters-can-a-lambda-expression-have-in-java
How many parameters can a lambda expression have in Java?
(p1,p2) -> { //Body of multiple parameter lambda } import java.util.function.*; public class LambdaExpression3 { public static void main(String args[]) { Message m = new Message(); m.printStringInteger("Java", 75, (String str, Integer number) -> { // multiple parameters lambda System.out.println("The values are: "+ str + " "+ number); }); } private static class Message { public void printStringInteger(String str, Integer number, BiConsumer<String, Integer> biConsumber) { biConsumber.accept(str, number); } } } The values are: Java 75 ·
🌐
Quora
quora.com › How-do-you-pass-multiple-parameters-to-one-method-in-Java
How to pass multiple parameters to one method in Java - Quora
Answer: When you create method signature then you have choice to create method with no parameter, Single parameters or multiple parameters for more details please go through below method signature. Method without parameter accessModifier returntype methodName() public void demoMethod() {} Met...
🌐
Kansas State University
textbooks.cs.ksu.edu › cc210 › 06-methods › 09-java › 02-parameters
Parameters :: CC 210 Textbook
June 27, 2024 - In Java, we can add parameters to a method declaration by placing them in the parentheses () at the end of the declaration. Each parameter is similar to a variable declaration, requiring both a type and an identifier. We can also define multiple parameters, separated by commas ,.
🌐
W3Schools Blog
w3schools.blog › home › java 8 lambda expression multiple parameters
Java 8 lambda expression multiple parameters
April 14, 2018 - package com.w3schools; @FunctionalInterface interface AddInterface{ void add(int a, int b); } public class LambdaExpressionExample { public static void main(String args[]){ //Using lambda expressions AddInterface addInterface=(a, b)->{ System.out.println(a + b); }; addInterface.add(10, 20); } }
🌐
AlgoCademy
algocademy.com › link
Function Parameters And Arguments in Java | AlgoCademy
Here is a complete example demonstrating the use of function parameters and arguments in Java: public class Main { // Function with one parameter static void sayHello(String audience) { System.out.println("Hello " + audience); } // Function with multiple parameters static void sayHello(String name, int age) { System.out.println(name + ", aged " + age); } public static void main(String[] args) { // Calling functions with arguments sayHello("humans"); // Output: Hello humans sayHello("John", 30); // Output: John, aged 30 sayHello("Mary", 26); // Output: Mary, aged 26 // Using variables as arguments String name = "Andy"; int age = 28; sayHello(name, age); // Output: Andy, aged 28 } }
🌐
Its All Binary
itsallbinary.com › home › java 8 – lambda & method reference (multiple arguments method)
Java 8 - Lambda & Method reference (Multiple arguments method) - Its All Binary - Coding Posts, Examples, Projects & More
November 25, 2018 - In case of a functional interface whose method has multiple arguments, below example shows how to implement it using lambda or method reference.
🌐
InfoWorld
infoworld.com › home › software development › programming languages › java
Too Many Parameters in Java Methods, Part 6: Method Returns | InfoWorld
November 18, 2013 - One other variation on this approach is to return a Java Map that maps arbitrary keys to their associated value. As with the other solutions, this approach places undue burden on the client to know what those keys are and to access the map values through those keys. The next code listing contains several of these less attractive approaches for returning multiple values without hijacking the method parameters to return multiple values.
🌐
Scaler
scaler.com › home › topics › what are method parameters in java?
What are Method Parameters in Java? - Scaler Topics
September 22, 2023 - Methods can return values using ... operations to the calling code. Methods can have multiple parameters in Java, enabling them to accept and process multiple values passed during method calls....