Question

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.

Was it helpful?

Solution

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")
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top