This week's book giveaways are in the Cloud and AI/ML forums. We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line! See this thread and this one for details.
You can pass parameters into a java app from the command line. They are read into the array when you start your main "public static void main (String args)". Spaces in the command line are the delimiters. You can reference these parameters by referencing args or args or args...for however many parameters you've passed in. Norm
Originally posted by Pauline McNamara: Hello, Got stumped early on working through a java book (B.Eckel). Can anyone explain what it means to index into the command line array of String? This is not homework, I'm working on my own. Thanks.
Hi Pauline, What he means is, to use an index (variable to go through each element of the array). so if a is an array of 10 elements., we can denote an element of the array by a[i], with i, the index, going from 1 to 10. so, since args is also an array, args would be the first element of the array...args is a special array in that it holds whatever we type at the command line, when we run the program...and holds it as a string. hence the declaration String args in main(). so if u were to say java somefile hi there, then args would be "hi", and args would be "there". the thing to remember is that even if u enter a number, instead of hi or there would be treated as a string. so to print out those 2 words, all we need to say is println args and println args. hope this made sense. good luck.