As it is written on previous answers, it is varargs
and declared with ellipsis
(...)
Moreover, you can either pass the value types and/or reference types or both mixed (google Autoboxing). Additionally you can use the method parameter as an array as shown with the printArgsAlternate
method down below.
Demo Code
public class VarargsDemo {
public static void main(String[] args) {
printArgs(3, true, "Hello!", new Boolean(true), new Double(25.3), 'a', new Character('X'));
printArgsAlternate(3, true, "Hello!", new Boolean(true), new Double(25.3), 'a', new Character('X'));
}
private static void printArgs(Object... arguments) {
System.out.print("Arguments: ");
for(Object o : arguments)
System.out.print(o + " ");
System.out.println();
}
private static void printArgsAlternate(Object... arguments) {
System.out.print("Arguments: ");
for(int i = 0; i < arguments.length; i++)
System.out.print(arguments[i] + " ");
System.out.println();
}
}
Output
Arguments: 3 true Hello! true 25.3 a X
Arguments: 3 true Hello! true 25.3 a X