By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,541 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,541 IT Pros & Developers. It's quick & easy.

something like C-language printf function

P: 13
Can somebody show me, how to declare function with variable number of parameters in Java? I want to provide method similar to C-language printf function.

Thanks in adavne!

M.
Dec 18 '06 #1
Share this Question
Share on Google+
3 Replies


10K+
P: 13,264
Can somebody show me, how to declare function with variable number of parameters in Java? I want to provide method similar to C-language printf function.

Thanks in adavne!

M.
This is only available from java 5.0 upwards



Expand|Select|Wrap|Line Numbers
  1.  
  2. import static java.lang.System.out;
  3. public class VargArgs {
  4.  public static void main(String ... args) { //Can even use them here
  5.   myPrintf("one");
  6.   myPrintf("one", "two");
  7.  } 
  8.  public static void myPrintf(String ... args) {
  9.   for(String s : args) {
  10.    out.println(s);
  11.   }
  12.  }
  13. }
  14.  
  15.  
Dec 18 '06 #2

P: 13
Thanks again for your answer.

King Regards

M.
Dec 18 '06 #3

10K+
P: 13,264
Thanks again for your answer.

King Regards

M.
Sorry I don't remember giving you help around here. Have we met before?
Dec 18 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.