Reputation: 393
I didn't know what to look for so i couldn't google this one but..
What are String...
parameters called as ?
And how do you get individual strings when more than one String
object is passed through a String...
object ?
Upvotes: 2
Views: 136
Reputation: 2764
this is a feature introduced with jdk 1.5. basically the last parameter of a method can be declared as ... and that means
Upvotes: 0
Reputation: 533492
A String...
is syntactic sugar for an String[]
and you access the values of the String array just like any other String array. In fact you can write this simple method.
public static <T> T[] asArray(T... ts) {
return ts;
}
This takes a vararg array can returns an array.
The key difference is that you can write
asArray(1, 2, 3); // much shorter.
instead of having to write
asArray(new Integer[] { 1, 2, 3 });
Upvotes: 2