This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Var-args  RSS feed

 
Vatsal Upadhyaya
Greenhorn
Posts: 18
Android Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain what is var-args..??
 
fred rosenberger
lowercase baba
Bartender
Posts: 12527
48
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in a nutshell, you can say "i don't know exactly how many of THESE will be passed in, so let them pass in as many as they want and stick them into an array".
 
James X Peterson
Whizlabs Java Support
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normal Method

public void call(int a,int b){....}

VarArg Method

public void call(int... a) {....}

The normal method above takes no more than 2 parameters of int type.
The varargs method takes as many number of parameters as you give of int type only.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16006
87
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First search result for "java varargs" on Google: Varargs

(Note: "What is X" questions most often can be answered very quickly by searching Google for "X").
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!