What do the 3 dots following String in the following method mean?
public void myMethod(String... strings) {
// method body
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It means that zero or more String objects (or a single array of them) may be passed as the argument(s) for that method.
See the "Arbitrary Number of Arguments" section here: http://java.sun.com/docs/books/tutorial/java/javaOO/arguments.html#varargs
In your example, you could call it as any of the following:
Important Note: The argument(s) passed in this way is always an array – even if there’s just one. Make sure you treat it that way in the method body.
Important Note 2: The argument that gets the
...must be the last in the method signature. So,myMethod(int i, String... strings)is okay, butmyMethod(String... strings, int i)is not okay.Thanks to Vash for the clarifications in his comment.