Variable parameters in Java

Source: Internet
Author: User

variable parameters have been introduced from Java5, which is the extension of Java methods and Arrays!

The parameters that can be accepted in a method are no longer a fixed number, but are determined by how much specific requirements are passed.

define the format: return value type Method Name ( parameter type ... formal parameters ) {}

features of variable parameters:

Can only appear at the end of the parameter list;

... Between the variable type and the variable name, there are no spaces before and after it can be ;

When you call a method of a mutable parameter, the compiler creates an array for the mutable parameter implicitly, accessing the mutable parameter as an array in the method body.

 PackageReviewdemo;Importjava.util.Arrays; Public classDemo6 { Public Static voidMain (string[] args) {int[]age = {1,2,3,69,36,636,459};    Show (age); }         Public Static voidShowint.. a) {//This is what is written here is the variable parameter, and the function of the array! //print out the array! System.out.println (Arrays.tostring (a)); }}    

Variable 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.