1. 程式人生 > >JAVA中“...”三個點

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;