Methods with variable-length argument list (varargs)

A method with a variable length parameter list has the ability to take different number of arguments.
These methods are declared using three dots after the data type of the last argument in the list. Only one parameter in the list may be declared as a varargs parameter and that parameter has to be the last one in the list.

Varargs methods are handled purely by the compiler. To the Java interpreter, such a method is indistinguishable from declaring an array instead of using three dots after the data type.

This is an example of a varargs method:

The above method can be called with zero or more arguments passed to it. All of the statements below are valid calls to the method:

Since a varargs argument is treated as an array you may also call the method like this:

Search for more Java info on this site here:
Custom Search

Please type any questions here.