…表示可變長參數,就是說這個位置可以傳入任意個該類型參數,簡單來說就是個數組。
(視頻教程推薦:java課程)
代碼示例:
1. testPoints(7); 2. testPoints(7,9,11); 3. testPoints(new Integer[]{7,9,11}); 1. public static void testPoints(Integer... itgr){ 2. if(itgr.length==0){ 3. System.out.println("沒有Integer參數傳入!"); 4. }else if(itgr.length==1){ 5. System.out.println("1個Integer參數傳入!"); 6. }else{ 7. System.out.println("the input string is-->"); 8. for(int i=0;i<itgr.length;i++){ 9. System.out.println("第"+(i+1)+"個Integer參數是"+itgr[i]+";"); 1.1個Integer參數傳入! 2.the input string is--> 3.第1個Integer參數是7; 4.第2個Integer參數是9; 5.第3個Integer參數是11; 6.the input string is--> 7.第1個Integer參數是7; 8.第2個Integer參數是9; 9.第3個Integer參數是11;