In the Java aspect, the arguments are followed by three dots (...). The meaning

Source: Internet
Author: User
private void Removetempfiles (String ... fileNames) {for
(string filename:filenames) {
try {
new File (Filena Me). Delete ();
} catch (Exception e) {
}
}
}

Where the String ... fileNames means.
Three dots after the type (String ...)., starting with Java 5, the Java language supports a new approach to method parameters, called variable-length argument lists, whose syntax is the type heel ..., which means that the parameters accepted here are 0 to more objects of type object, or a object[]. For example, we have a method called Test (string...strings), so you can also write method test (), but you can't write test (string[] strings), which will cause a compile error, and the system prompts for a duplicate.

In use, for Test (string...strings), you can use test () directly to invoke, marked without parameters, can also be used to test ("AAA"), can also use test (new string[]{"AAA", "BBB"}).

Also, if you have both the test (string...strings) function and the test () function, we will use the test () function preferentially when we call Test (). Only if the test () function is not available, we call Test () and the program goes to test (string...strings).

Example one:

public class Ttest {
//private static int A;
public static void Test (int ... a) {for
(int i=0;i<a.length;i++) {
System.out.println (a[i]);
}
public static void Main (string[] args) {
ttest.test (1,2);
}
Case TWO:
String ... excludeproperty represents an indefinite parameter, which means that you can pass in multiple string objects when you invoke this method.
public static void Main (string[] args) {
//test, passing in multiple parameters
test ("Hello", "World", "13SD", "Country", "Cum", "ICT"); c12/>} public

static void Test (String ... arguments) {for
(int i = 0; i < arguments.length; i++) {
syste M.out.println (Arguments[i]);

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.