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
🌐
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.
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 133321 › how-methods-with-multiple-parameters-are-declared
java - How methods with multiple parameters are ... | DaniWeb
Overloading lets you define multiple methods with the same name but different parameter lists, and the compiler selects the most specific match. Variable-arity parameters (varargs) use T... as syntactic sugar for an array; only one is allowed and it must be last. If you hit “method X cannot be applied to given types,” verify count/order/types or an unintended overload. Formal parameter rules are in the JLS Formal Parameters. class Example { static String join(int id, String first, String last) { // declaration + definition return id + ": " + first + " " + last; } static void demo() { String r1 = join(42, "Ada", "Lovelace"); // matches number/order/types String r2 = join("one", "two", "three"); // calls overload below } static String join(String...
🌐
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
In this example, the greetPerson() method is called twice, each time with different values for the name and age parameters. By understanding the concept of method parameters, you can create more flexible and reusable Java methods, which is an ...
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 ·
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › function › BiFunction.html
BiFunction (Java Platform SE 8 )
3 weeks ago - Java™ Platform Standard Ed. 8 ... This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Find elsewhere
🌐
Kansas State University
textbooks.cs.ksu.edu › cc210 › 06-methods › 09-java › 02-parameters
Parameters :: CC 210 Textbook
June 27, 2024 - That argument will be stored as the parameter’s variable in foo(): ... Here’s another example. In this case, we are writing two methods, foo() and bar(). They accept multiple parameters, and in main() we call each method using arguments for each parameter.
🌐
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 - In Java, there is a Function <X, R> and BiFunction <X, Y, R>, where X and Y are types of input parameters, and R is the output parameter type. But functions with three and more input parameters must be determined by yourself.
🌐
Flylib
flylib.com › books › en › 2.254.1 › declaring_methods_with_multiple_parameters.html
Declaring Methods with Multiple Parameters | Methods: A Deeper Look
For example, the expression "hello " + "there" creates the String "hello there". In line 24 of Fig. 6.3, the expression "Maximum is: " + result uses operator + with operands of types String and double. Every primitive value and object in Java has a String representation.
🌐
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 - Parameter Objects are helpful when there are many required parameters, and immutability is important. At the same time, we use Java Beans when we need to modify the object’s state at different times during its lifetime. Let’s see an example of calling a method by passing multiple arguments ...
🌐
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); } }
🌐
InfoWorld
infoworld.com › home › software development › programming languages › java
Too Many Parameters in Java Methods, Part 6: Method Returns | InfoWorld
November 18, 2013 - One of these is returning an array or collection of Object instances with each Object being a disparate and distinct and often unrelated “thing.” For example, the method might return three values as three elements of an array or collection. A variation of this approach is to use a pair ...
🌐
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...
🌐
Home and Learn
homeandlearn.co.uk › java › java_method_parameters_part2.html
java for complete beginners - more parameters
The values (parameters) that we specified are between the round brackets, along with the return method, void.
🌐
AlgoCademy
algocademy.com › link
Function Parameters And Arguments in Java | AlgoCademy
In this lesson, we explored the concept of function parameters and arguments in Java. We learned how to define functions with parameters, call functions with arguments, and handle multiple parameters. Understanding these concepts is essential for writing flexible and reusable code.
🌐
Scaler
scaler.com › home › topics › what are method parameters in java?
What are Method Parameters in Java? - Scaler Topics
September 22, 2023 - A. Yes, methods can have multiple parameters in Java, enabling them to accept and process multiple values passed during method calls. Q. Can Java methods return values based on parameters?