something like C-language printf function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kenk
    New Member
    • Nov 2006
    • 13

    #1

    something like C-language printf function

    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.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by kenk
    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



    Code:
     
    import static java.lang.System.out;
    public class VargArgs {
     public static void main(String ... args) { //Can even use them here
      myPrintf("one");
      myPrintf("one", "two");
     } 
     public static void myPrintf(String ... args) {
      for(String s : args) {
       out.println(s);
      }
     }
    }

    Comment

    • kenk
      New Member
      • Nov 2006
      • 13

      #3
      Thanks again for your answer.

      King Regards

      M.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by kenk
        Thanks again for your answer.

        King Regards

        M.
        Sorry I don't remember giving you help around here. Have we met before?

        Comment

        Working...