Possible Duplicate:
What is the ellipsis (…) for in this method signature?
java: how can i create a function that supports any number of parameters?
well i'm trying to figure out some examples and I found this kind of array definition for arguments in the main method. What's so special about this "..." and what's the difference between a normal String[] args?
Thanks
Use the clone method of the array.
ArrayList is backed by an Array while HashSet is backed by an HashMap. Duplicates : ArrayList allows duplicate values while HashSet doesn't allow duplicates values.
The references in the new Array point to the same objects that the references in the original Array point to. In contrast, a deep copy of an Array copies the elements and everything directly or indirectly referenced by the elements. The clone is of the same Type as the original Array.
That's a notation from Java 5 for variable length argument lists. It is roughly equivalent to a String array, but lets you pass individual parameters that are combined into an array automatically.
void mymethod(String... a) {
for (String s : a) {
...
}
}
mymethod("quick", "brown", "fox");
This makes sense only when you plan to call a method from your program, so I do not see why it would be desirable to use this syntax for your main(). It will work, however.
The elipsis (...) are varargs. They are used when you want to create a method with any number of arguments. Oracle explains how varargs work in detail here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With