可变参数:其本质就是一个数组,自动将元素封装成数组。
格式:
方法名(类型... 参数名) { ... code ... }
注意:可变参数必须再参数列表的结尾
用法如下:
1 public int add(int... p_intParams){ 2 int sum = 0; 3 for(int i=0;i<p_intParams.length;i++){ 4 sum+=p_intParams[i]; 5 } 6 return sum; 7 }