"Thinkinginjava" 5, with an object array as a parameter

Source: Internet
Author: User

/*** 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.