mutable parameters in Java

Source: Internet
Author: User

1. What is a variable parameter

Variable parameters are a new feature of JDK1.5, allowing a single way to accept any number of arguments

public static void Main (string[] args) {print ("a");p rint ("A", "B");p rint ("A", "B", "C"), and public static void print (String ... s) {for (String a:s) System.out.println (a);}

2. How the variable parameter is executed

When a variable parameter is used, an array is created where it is called, and the array length is the actual number of arguments;

The arguments are then put into the array, and finally the array is passed to the method

3. When to use variable parameters

mutable parameters, as defined by variable parameters, are very useful in accepting any number of objects;

Example of a mutable parameter in a JDK source code:

String.Format (String format, Object ... args), this method can accept any number of arguments

String.Format ("An Integer:%d", i); String.Format ("An integer:%d and a string:%s", I, s);

 

mutable parameters in Java

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.