Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Comparison ?

 
Madhu Iyer
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someonew tellme how to go about srting comparison.

I have the input from the System as b.readLine() and I want to compareit with String "Exit".

if i write
if(b.readLine()=="Exit"){
// My code goes here
}

even after typing Exit it does not enter the IF Loop...........

HELP !!!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use "==" to compare Strings; use the "equals()" method.

if (myString.equals("Exit")) ...

"==" asks if two objects are the same physical object in memory, while "equals()" asks if they are interchangeable or equivalent, even if they are distinct objects.
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the real world of java.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic