+ 2

Why is main followed by a String type array? [Solved]

I always see main followed by String[ ]. Can it be anything else?

22nd Apr 2017, 3:57 PM
T R
T R - avatar
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.
22nd Apr 2017, 4:24 PM
Tashi N
Tashi N - avatar
+ 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.
22nd Apr 2017, 4:03 PM
Tashi N
Tashi N - avatar
+ 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?
22nd Apr 2017, 4:15 PM
T R
T R - avatar
+ 2
Fantastic Tashi. Thx
22nd Apr 2017, 4:28 PM
T R
T R - avatar