概念
案例
package lesson.l10_oop;/*** Illustration** @author DengQing* @version 1.0* @datetime 2022/7/1 14:53* @function 可变个数形参*/
public class ChangeableFormalParameter {public static void main(String[] args) {ChangeableFormalParameter parameter = new ChangeableFormalParameter();parameter.print("aa");parameter.print("aa", "bb");
// 也可以这样写parameter.print(new String[]{"aa", "bb"});parameter.print(0, "bb", "cc", "dd");}public void print(String str) {System.out.println(str);}public void print(String... strs) {for (int i = 0; i < strs.length; i++) {System.out.print(strs[i] + "\t");}System.out.println();}
/* public void print(String[]strs){}public void print(String... strs) {}这两个是一样的*/public void print(int i, String... strs) {System.out.println(i);for (String s :strs) {System.out.print(s + "\t");}System.out.println();}
}