Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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