• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compare CLI arguments with a string value  RSS feed

 
Charles Mulloy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 55783
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please avoid unexplained abbreviations like "CLI"; it is not obvious at first reading what they mean.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!