简体   繁体   English

String [] args与main方法中的String…args有何不同?

[英]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. 当我看到这两种技术可以通过main方法传递命令行参数时,我感到困惑。

I have seen this link in stackoverflow but still I don't get it. 我在stackoverflow中看到了此链接 ,但仍然不明白。

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. 1.首先,我们调用main并将参数分配为字符串数组。2。其次,我们调用main并带有变量no的参数。

It means that if you want to invoke the main method of a class that isn't the entry point, it's easier: 这意味着,如果要调用不是入口点的类的main方法,则会更容易:

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

vs: VS:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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