…表示可變長參數(shù),就是說這個(gè)位置可以傳入任意個(gè)該類型參數(shù),簡單來說就是個(gè)數(shù)組。
(視頻教程推薦: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參數(shù)傳入!"); 4. }else if(itgr.length==1){ 5. System.out.println("1個(gè)Integer參數(shù)傳入!"); 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)+"個(gè)Integer參數(shù)是"+itgr[i]+";"); 1.1個(gè)Integer參數(shù)傳入! 2.the input string is--> 3.第1個(gè)Integer參數(shù)是7; 4.第2個(gè)Integer參數(shù)是9; 5.第3個(gè)Integer參數(shù)是11; 6.the input string is--> 7.第1個(gè)Integer參數(shù)是7; 8.第2個(gè)Integer參數(shù)是9; 9.第3個(gè)Integer參數(shù)是11;