+ 1

Why does main function in java accepts only string array as arguments ?

static void main (string [] args) why only string ?

9th Nov 2016, 1:08 PM
Siddhesh Shirsat
Siddhesh Shirsat - avatar
3 Answers
+ 3
Because it stores the command line arguments which could be anything. It's best to accept them as an array of strings (there can be many) and later decide to cast them accordingly.
9th Nov 2016, 1:16 PM
Islay
Islay - avatar
+ 2
because strings can contain any type of value
9th Nov 2016, 10:35 PM
Maurizio Urso
Maurizio Urso - avatar
0
The main function can contain any type of parameters but in the case if we do not know what type of input would be given by the user, it is best to accept all the inputs as an array of strings and then convert the input data into the required data type by using the abstract String class
21st Nov 2016, 1:35 PM
Prarabdh Garg
Prarabdh Garg - avatar