aspose file tools*
The moose likes Cattle Drive and the fly likes args.length == 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "args.length == 1" Watch "args.length == 1" New topic
Author

args.length == 1

Nath Maniedeo
Greenhorn

Joined: Feb 15, 2008
Posts: 29
Question- So then, if ( args.length == 1 ) is that saying that if the args typed in is at least 1 character *or more ??*
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1362
    
  17
args is an array

If you say:

java MyJavaClass boots hat cane

then args holds three values, the Strings "boots", "hat", and "cane".
args.length is equal to 3 in this case.

Strings also can have a length, which we can find using the method length()
<code>String name = "Katrina Owen";</code>
<code>name.length()</code> is equal to 12.

Compare the two:

Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Originally posted by Nath Maniedeo:
if ( args.length == 1 ) is that saying that if the args typed in is at least 1 character *or more ??*

In this case we are checking that the length of the array of Strings that is named args is exactly one.

If you wanted to check that the String[] named args had a length of 1 or more, you could check
if ( args.length > 0 ) or
if ( args.length >= 1 )
but in this case (== 1), we are we are checking that the array of Strings has exactly one String (regardless of the length of that String).

args[0] is the reference to the first String in the array of Strings named "args".

Here are some links that may help.

http://www.coderanch.com/t/3572/Cattle-Drive/Command-Line-Arguments

http://www.coderanch.com/t/3619/Cattle-Drive/Stupid

http://www.coderanch.com/t/4912/Cattle-Drive/assignment

http://www.coderanch.com/t/4957/Cattle-Drive/Questions-Assignment-Hundred


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Nath Maniedeo
Greenhorn

Joined: Feb 15, 2008
Posts: 29
this helps, thank you both so much.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: args.length == 1