Reputation: 1021
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.
Upvotes: 0
Views: 142
Reputation: 97691
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")
}
}
Upvotes: 4