Passing a Variable Number of Parameters to a Method in Java
If you have a list of objects that you want to pass to a method, you can always use an Array or a Collection of some sort (such as ArrayList). However, sometimes you want to be able to pass in a variable number of arguments without using these complex types in advance. This is easy to do with the following syntax. (Please note that values gets turned into an array of String objects in this example.)
public void methodName(String ... values)
{
for (String value : values)
System.out.println(value);
}
This only works in Java 1.5+.
You’ve got to be kidding me-it’s so tranpsnaretly clear now!