• Post Reply Bookmark Topic Watch Topic
  • New Topic

Args[] array in main method  RSS feed

 
Colm Dickson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for that reply. It was something I never really dwelled on before but definitely makes sense.

Regards
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!