• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Var-args

 
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: 12188
34
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
Saloon Keeper
Posts: 15459
42
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").
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic