Variable parameters (Varargs)
Mutable parameters enable programmers to declare a method that accepts a variable number of parameters. Note that the mutable parameter must be the last parameter of the method declaration.
A mutable parameter is essentially an array, and for a variable argument, we can either pass a discrete value or pass an array object. But if we define the parameters in the method as arrays, we can only pass the array object and not pass the discrete values.
A mutable parameter must be used as the last parameter of a method parameter, that is, a method cannot have two or more mutable parameters of more than two.
Public class varargstest { public static int sum (int ... nums) { int sum = 0; for (int num : nums) { sum += num; } return sum; } Public static void main (String[] args) { int ret = sum (1,2,4,7); system.out.println (ret); ret = sum (1,7); system.out.println (ret); &nbSp; ret = sum (new int[]{1,7}); //int ... equivalent to INT[]        SYSTEM.OUT.PRINTLN (ret); }}
Java record -78-variable parameters