When do you use varargs in Java?
问题 I'm afraid of varargs. I don't know what to use them for. Plus, it feels dangerous to let people pass as many arguments as they want. What's an example of a context that would be a good place to use them? 回答1: Varargs are useful for any method that needs to deal with an indeterminate number of objects . One good example is String.format. The format string can accept any number of parameters, so you need a mechanism to pass in any number of objects. String.format("This is an integer: %d",