Java variable number or arguments for a method
问题 Is it possible to declare a method that will allow a variable number of parameters ? What is the symbolism used in the definition that indicate that the method should allow a variable number of parameters? Answer: varargs 回答1: That's correct. You can find more about it in the Oracle guide on varargs. Here's an example: void foo(String... args) { for (String arg : args) { System.out.println(arg); } } which can be called as foo("foo"); // Single arg. foo("foo", "bar"); // Multiple args. foo(