+ 3

Why main take string as argument? 💭

24th Apr 2017, 7:20 AM
Parav Aneja
Parav Aneja - avatar
2 Answers
+ 12
in public static void main(String args[]) args is an array of console line argument whose data type is String. in this array, you can store various string arguments by invoking them at the command line simply to see what it stores you can put this in your main method to see yourself for(int i = 0; i < args.length; i++) { System.out.println("Argument is: "+args[i]); }
24th Apr 2017, 8:13 AM
adeel salim
adeel salim - avatar
+ 7
String is non primitive datatype so it is easy to convert any other primitive datatypes like int, double,etc.Commonly we get string array and converts it into a required type. If there is any other reasons behind this?
9th May 2017, 1:57 PM
kiruthika .s
kiruthika .s - avatar