How can I create a Java method that accepts a variable number of arguments?

前端 未结 7 746
野的像风
野的像风 2020-11-28 07:51

For example, Java\'s own String.format() supports a variable number of arguments.

String.format(\"Hello %s! ABC %d!\", \"World\", 123);
//=>          


        
7条回答
  •  余生分开走
    2020-11-28 08:24

    This is just an extension to above provided answers.

    1. There can be only one variable argument in the method.
    2. Variable argument (varargs) must be the last argument.

    Clearly explained here and rules to follow to use Variable Argument.

提交回复
热议问题