Get whole arguments string
Is there a way to get the whole arguments string without enumenrate String [] args?
Thanks in advance
Is there a way to get the whole arguments string without enumenrate String [] args?
Thanks in advance
As of java 5 you have two options:
public static void main(String[] argv) { // code }
public static void main(String... argv) { // code }
... if you don't like it, go back to VB ...
public class StringExample {
public static void main(String[] args) {
String[] test = {"hello", "world"};
System.out.format("[%s]%n", join(test));
}
public static String join(String... v) {
StringBuilder b = new StringBuilder();
for(String s : v) {
b.append(s).append(' ');
}
int length = b.length() - 1;
if (length >= 0)
b.setLength(length);
return b.toString();
}
}
> > public class StringExample {
>public static void main(String[] args) {
>String[] test = {"hello", "world"};
>System.out.format("[%s]%n", join(test));
> }
>
>public static String join(String... v) {
>StringBuilder b = new StringBuilder();
>for(String s : v) {
> b.append(s).append(' ');
> }
> int length = b.length() - 1;
> if (length >= 0)
> b.setLength(length);
> rn b.toString();
>}
>
nice.
I couldn't find docs about the (String... argv) version. Just tryed it and it seems identical. Where's the difference?
> I couldn't find docs about the (String... argv)
> version. Just tryed it and it seems identical.
> Where's the difference?
The only difference is how you may invoke the method:
void f(String... a) {}
void method(String[] v) {
f(v); //as always
f("hello", "world");
}