This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

var args doubt

 
aditi mudholkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.
i have not been able to understand the var-args syntax and in what way should the var arg be the last of a method's argument.
could you explain with an example.
thanks
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aditi mudholkar:
hi.
i have not been able to understand the var-args syntax and in what way should the var arg be the last of a method's argument.
could you explain with an example.
thanks


Basically this is correct.

,

but this is not

 
aditi mudholkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i know the syntax. but the code like

void display(int num,string ....args)
what does the .... imply???
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can declare

public void static main(String... a){

}
thats means you can pass variable number of Strings each time you call main.
Is that clear.

like
java SampleProgram one two three
java SampleProgram write until you satisfy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic