I found it very confusing that the command line arguments do not appear to follow the rules for strings. For example, args.length() is not valid. I believe this would be valid for a string declared as a variable.
Command line arguments follow the rules for an array of Strings, because that's what they are. An array has a length field and not a length() method, while a String has a length() method but not a length field. (Why this is I don't know, but we're stuck with it.) Assuming you've declared you main method thus: <code><pre> public static void main(String[] args) {</pre></code> ...then args refers to the whole array, and args[0] refers to the first element in the array, which is a String. So, if you want to know how many command-line arguments there are, use args.length. To find the length of the first argument (assuming it exists), use args[0].length(). Make sense?
"I'm not back." - Bill Harding, Twister
Betty Reynolds
Ranch Hand
Joined: Feb 16, 2000
Posts: 111
posted
0
Thanks again Jim. Your clarifications are extremely helpful.