Possible Duplicate:
What is “String args[]”? in Java
So I recently (well, three days ago) started teaching myself Java, with absolutely zero previous programming experience unless you count HTML/CSS.
Now I’ve been looking through both books and online tutorials, including the Sun tutorials. I don’t quite understand what the purpose of (string args[]) in a method is.
What I’ve got from looking online is that when using the console to run a program, it substitutes whatever comes after “>Java myprogram” in place of the “args”.
Firstly, is that correct? If so, why would you do that?
Cheers!
The
String[] argswhich can be written asString args[]orString ... argsis an array of the arguments you gave the program.So you can give your program inputs on the command line. It isn’t used in Java programs so often but it is quite commong for command line utilities to take arguments e.g.
In this case the
MyClass.javais an argument.Or like the following has three arguments.