I am getting an error in the below code when I change the string array argument in go method from String...y to String y[]. Can someone please explain why ?
public class scjp2 {
public static void main(String[] args) {
new scjp2().go( 1,"hi");
new scjp2().go( 2,"hi", "world");
}
public void go( int x,String...y) {
System.out.print(y[y.length - 1] + " ");
}
}
Also can someone explain why do I need to have the String...y argument as the last argument in the method
example:
public void go( int x,String...y) // correct way
public void go( String...y,int x) // wrong way