my dog learned polymorphism
The moose likes Beginning Java and the fly likes String Comparison ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Comparison ?" Watch "String Comparison ?" New topic

String Comparison ?

Madhu Iyer

Joined: Dec 27, 2005
Posts: 4
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
// My code goes here

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

HELP !!!
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
Welcome to the real world of java.

Money for nothing and Java for Free
I agree. Here's the link:
subject: String Comparison ?
jQuery in Action, 3rd edition