Java – Function with variable number of arguments

c++functionjava

As the title says I need to know if there is a corresponding syntax as java's ... in method parameters, like

void printReport(String header, int... numbers) { //numbers represents varargs
  System.out.println(header);
  for (int num : numbers) {
     System.out.println(num);
  }
}

(code courtesy of wikipedia)

Best Solution

Yes you can write something like this:

void PrintReport(string header, params int[] numbers)
{
    Console.WriteLine(header);
    foreach (int number in numbers)
        Console.WriteLine(number);
}