Variadic function

From Rosetta Code
Revision as of 22:02, 1 June 2008 by rosettacode>Mwn3d (Created task...I think this is an OK name for it)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Variadic function
You are encouraged to solve this task according to the task description, using any language you may know.

Create a function which takes in a variable number of arguments and prints each one on its own line.

Java

Works with: Java version 1.5+

Using ... after the type of argument will take in any number of arguments and put them all in one array of the given type with the given name. <java>public static void printAll(Object... things){

  for(Object i:things){
     System.out.println(i);
  }

}</java> This function can be called with any number of arguments: <java>printAll(4, 3, 5, 6, 4, 3); printAll(4, 3, 5); printAll("Rosetta", "Code", "Is", "Awseome!");</java>