• Post Reply Bookmark Topic Watch Topic
  • New Topic

Var args  RSS feed

 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what's the meaning of varargs? Is it like [B]method(int... args)[/B] where this method can have any no. of parameters.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, yes. And the identifier references an array holding those parameters.

See Varargs.
 
Hemanth Abburi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If the identifier references an array then why to use varargs when we can actually pass an array?

Thanks,
Hemanth
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because with varargs you can skip creating the array. Compare:

Now which do you prefer?

The compiler actually turns the second call into the first call so during runtime there is no difference, but your source code will be easier to read.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!