This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 2840
    
  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: 38057
    
  22
And please avoid unexplained abbreviations like "CLI"; it is not obvious at first reading what they mean.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compare CLI arguments with a string value
 
Similar Threads
Is there a way to instantiate anonymous inner class?
interface doubt
Constructor in Anonymous inner class
How to access Inner Anonymous Class
String side effect & how to overcome