可變參數
public static void main(String[] args) {
/**
* 可變參數簡化了
* int[] arr = {1,3};
* demo1(arr);
* 兩句代碼
*/
demo1(1,3);
}
//原始方法
public static void demo(int[] arr){
System.out.println(arr);
}
/**可變參數方法
* 底層還是傳入的數組 隱式將參數封裝在一個數組
*
* 使用時注意:使用可變參數,必須定義在參數列表最後一個(匹配完前面的參數,後面的全部封裝進數組)
* */
public static void demo1(int ... arr){
System.out.println(arr);
}