简体   繁体   中英

How String[] args different from String… args in the main method?

I got confused when I saw these two techniques through which we can pass our command line argument in main method.

I have seen this link in stackoverflow but still I don't get it.

My doubt is which is efficient between these two ways.

1.In first we are calling main and assigning parameter as a string array 2.In second we are calling main with variable no of arguments.

It means that if you want to invoke the main method of a class that isn't the entry point, it's easier:

class MyProgram1 {
    public static void main(String[] args) {
        MyProgram2.main(new String[] {"arg1", "arg2", "arg3"})
    }
}

vs:

class MyProgram1 {
    public static void main(String[] args) {
        MyProgram2.main("arg1", "arg2", "arg3")
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM