Answer the question
In order to leave comments, you need to log in
What are the differences between String[] args and String...args arrays?
Sometimes I see this kind of code
String [] args
и
String... args
Answer the question
In order to leave comments, you need to log in
An entry like methodName(T... args) is called varargs (Variable Arguments) The
convenience is that you can pass arguments at once and not create an array and the number of arguments can be 0 or N. Example:
public static void vargs(final String... strings) {
System.out.println(strings);
}
public static void arrs(final String[] strings) {
System.out.println(strings);
}
public static void main(final String... args) {
vargs(); // ok
vargs("1", "2"); // ok
arrs(); // compilation error
arrs(new String[] {"1", "2"}); // ok
}
public static void manyParams(final String... strings, final Integer number) {
// compilation error
}
public static void manyParams(final Integer number, final String... strings) {
// ok
}
https://docs.oracle.com/javase/1.5.0/docs/guide/la...
Difference:
public static void method1(final String arg0, final String[] arg1, final String arg2) {
}
public static void method2(final String arg0, final String... arg1, final String arg2) {
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question