| Author |
Args[] array in main method
|
Colm Dickson
Ranch Hand
Joined: Apr 04, 2009
Posts: 84
|
|
Hi all,
I never really thought about the args[] array in the main method until now and it struck me that it must be auto intiialised in size based on the number of arguments you pass to the command line. i.e. 3 arguments passed and the args[] array is created with 3 elements and its size is 3. Is this a correct assumption?
Also, if no arguments are passed, how come a test on this args[] arry being null returns false?
I'm aware that all arrays have their element intiailsed to the defaults of the type e.g. 0 for int, howver, if no arguments are passed then is the args[] array not just a null array with no elements? Can someone shed some light or point me in the direction of more information on this 'special' case?
Thanks,
Colm
|
 |
Tom Reilly
Rancher
Joined: Jun 01, 2010
Posts: 618
|
|
|
The arg array is always an array of Strings. If no arguments are passed then the size of the arg array is zero. But the array is still created. It just doesn't have any elements in it.
|
 |
Colm Dickson
Ranch Hand
Joined: Apr 04, 2009
Posts: 84
|
|
Thanks for that reply. It was something I never really dwelled on before but definitely makes sense.
Regards
|
 |
 |
|
|
subject: Args[] array in main method
|
|
|