Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

args.length == 1

 
Nath Maniedeo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9068
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nath Maniedeo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this helps, thank you both so much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic