+ 2
Why is main followed by a String type array? [Solved]
I always see main followed by String[ ]. Can it be anything else?
4 ответов
+ 15
String[ ] is used because it can hold other values as strings, too, e.g. integers, doubles and so on. If you want to pass an integer or another type you can parse it in main and check if it is valid.
So I guess the reason to choose a String[ ] is that it can be used for general purpose.
+ 14
You can pass arguments to your program if you start it via console/ide, see:
https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html
All arguments will be stored in the String array named args and you can access and handle them in your program.
+ 3
Thank you. So in summary, because the arguments being passed to main are characters ie. strings, that is why main is always followed by a string array?
+ 2
Fantastic Tashi. Thx