• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

args.length == 1

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??*
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

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

https://coderanch.com/t/3619/Cattle-Drive/Stupid

https://coderanch.com/t/4912/Cattle-Drive/assignment

https://coderanch.com/t/4957/Cattle-Drive/Questions-Assignment-Hundred
 
Nath Maniedeo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this helps, thank you both so much.
 
reply
    Bookmark Topic Watch Topic
  • New Topic