I've read java doc.
I cannot understand what varargs(....) is .
Can someone give me a very very simple example?
Mike
class VeryVerySimpleExample {
public static void printArgs(String...args) {
String[] array = args;
System.out.println(array.length + " " + args.length);
for (int i = 0; i < args.length; ++i) {
System.out.println(args
);
}
}
public static void main(String[]args) {
printArgs();
printArgs("Hello");
printArgs("Hello", "World");
printArgs(args);
printArgs(new String[] {"This", "is", "not", "a", "drill"});
}
}
So, hopefully my example shows you that:
A vararg is simple syntactic sugar for an array.
The Java compiler will automatically create a new array if one isn't
passed in.
There are a few other details to know about, but thats the basis of
it.
Hope this helps,
Daniel.