GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Compare CLI arguments with a string value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compare CLI arguments with a string value" Watch "Compare CLI arguments with a string value" New topic
Author

Compare CLI arguments with a string value

Charles Mulloy
Ranch Hand

Joined: Oct 25, 2009
Posts: 30


I tried something similar to the above code. When I test it...



it will repeat what you told it to test but the if statement is not coming up true. How did I mess up this time?

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

It's a very common mistake for new Java programmers. You need to compare objects (including Strings) with .equals():

args[0].equals(find)

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
And please avoid unexplained abbreviations like "CLI"; it is not obvious at first reading what they mean.
 
GeeCON Prague 2014
 
subject: Compare CLI arguments with a string value