Language syntax
Java variable arity parameters
The final parameter can accept zero or more individual elements or an existing array. Inside the body it has array type.
Formal Syntax & Structure
java syntaxjava
static int sum(int... values)Working Example
Example Snippetjava
public class Main { static int sum(int... values) { int total = 0; for (int value : values) { total += value; } return total; } public static void main(String[] args) { System.out.println(sum(2, 3, 4)); System.out.println(sum()); int[] stock = {7, 8}; System.out.println(sum(stock)); }}