Variable arguments with Java Tiger (J2SE 5.0)

In Java 5.0 a function can accept a variable number of optional parameters. In a method similar to Javascript and C, using Varargs

To give an example, the below function argtest can be called with a variable number of arguments, for example argtest("a","b","c"). The arguments variable takes the form of an array, in the below example.

 
 void argtest(String ... arguments) 
 {
	for (String argument : arguments) 
	{      
		System.out.println(argument);
	}    
 }

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2015.