Varargs (Variable Arguments)
Varargs (introduced in Java SE 5) allows you to pass 0, 1, or more params to a method's vararg param.
They let you pass any number of objects of a specific type.This reduces the need for overloading methods that do the similar things. For example,
public static void AsSimpleAsThis(String... params)
// params represents a vararg.
{
}
AsSimpleAsThis(s1,s2,s3); // pass 3 strings
params[0] is the first string
params[1] is the second string
params[2] is the third string
AsSimpleAsThis("hello",s2); // pass 2 strings
params[0] is the first string (="hello")
params[1] is the second string
AsSimpleAsThis("hey")
params[0] is the first string=hey
The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments. Varargs can be used only in the final argument position.