1

I have gone through a note on var-args in java. I wondered what is the difference it make with the array parameter while calling a method.

public void doSomething(int[] a){
   // some logic here
}   
public void doSometing(int... a){
  // some logic here
}

the above two methods were called by

int[] x={1,2,3,4,5};
doSomething(x);

is both of them are same or some difference exists?

and is it possible to overload these two methods?

sarath kumar
  • 360
  • 2
  • 15

1 Answers1

2

The two method signatures are the same, and they do not allow overloading.

The only difference is that calling doSomething(1, 2, 3) with the vararg signature is allowed, while calling the same with the array signature results in an error.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523