Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compare CLI arguments with a string value

 
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: 2987
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
Sheriff
Pie
Posts: 49451
64
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic