VarArgs3.java
Select all
/* VarArgs3.java CIS 260 2/16/2005 David Klick Demonstrates the use of the new Java 1.5 variable argument feature, syntax, and usage. */ public class VarArgs3 { public static void main(String[] args) { System.out.println(concat("This", "is", "my", "number", 1, "test" , "string.")); } // This method concatenates all the parameters into one // String separated by spaces static String concat(Object... arr) { StringBuilder sb = new StringBuilder(); for (Object o : arr) sb.append(o).append(" "); return sb.toString(); } } /* Sample output: This is my number 1 test string. */