Java mutable parameter list

Source: Internet
Author: User

One, the use of indefinite parameter list:

void f (String ... strs); // here the parameter type is string, the number of arguments is unknown, "," delimited append & This parameter can be dynamically generated an array based on the number of arguments, and then passed into the method execution

Two, the indefinite parameter has two stipulation

1, the parameter list of the method has only one parameter of indefinite length;  

  2. The position of an array of indefinite length must be the last parameter, or it cannot be compiled.

When this method is actually called, the JVM will not know how long the previous indefinite length parameter is, and where the next parameter starts

Third, code example

    /*** Function: Whether multiple parameters are not NULL, "", "" .<br/> * date:2017 June 20 pm 4:03:01 <br/> * *@author[email protected] *@paramparams *@return     */     Public StaticBoolean Notblank (String ... params) {if(NULL= = Params | | Params.length = = 0) {//the number of params is treated as an array            return false; }         for(String param:params) {if(Stringutils.isblank (param)) {return false; }        }        return true; }

Java mutable parameter list

Related Article

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.