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

前端 未结 7 734
野的像风
野的像风 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:18

    The following will create a variable length set of arguments of the type of string:

    print(String arg1, String... arg2)
    

    You can then refer to arg2 as an array of Strings. This is a new feature in Java 5.

提交回复
热议问题