/*** book: "Thinking in Java" function: An object array as a parameter * file: varargs.java* time: October 6, 2014 20:04:18* Author: cutter_point*/package Lesson5initializationandcleanup;class A{}public class VarArgs {static void PrintArray (Object [] args) {for (object Obj:ar GS)//output args inside the object System.out.println (obj+ "");//foreach syntax System.out.println (); NewLine}static void PrintArray2 (Object ... args)//This variable parameter list {for (object Obj:args)//output args inside the object System.out.println (obj+ "");//foreach syntax System.out.println (); NewLine}public static void Main (String [] args) {PrintArray (new object[]{new Integer, New Float (3.14), New Double (11.11)} );//Inside is the initialization of an anonymous Object array printArray2 (new Object[]{new Integer, New Float (3.14), New Double (11.11)});// Inside is the initialization of the anonymous Object array printArray2 (3.14F, 11.11);p Rintarray (New object[]{"One", "one", "three"});//character Initialization printArray2 ("One", "one", "three");//character initialization PrintArray (new Object[]{new A (), new A (), New A ()});}
Output Result:
47
3.14
11.11
47
3.14
11.11
47
3.14
11.11
One
Both
Three
One
Both
Three
[Email protected]
[Email protected]
[Email protected]
"Thinkinginjava" 5, with an object array as a parameter