This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String ".equals" method always returning true?" Watch "String ".equals" method always returning true?" New topic
Author

String ".equals" method always returning true?

Billy Nicholson
Greenhorn

Joined: Jun 16, 2011
Posts: 8
Don't know where to go from here. Anything I could check?



I press any button which triggers an ActionEvent and I get:

Show/Hide Slave
Show/Hide Slave equals Show/Hide Slave
Show/Hide Slave equals Map

as the output.

Edit: Not only is it always returning true, it is also ignoring if/else flow.
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
remove the semicolon at the end of line 11
Billy Nicholson
Greenhorn

Joined: Jun 16, 2011
Posts: 8
.....*facepalm* Woooow... I feel like an idiot. Thanks a bunch.
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
Billy Nicholson wrote:.....*facepalm* Woooow... I feel like an idiot. Thanks a bunch.


No reason to feel silly, I think this is actually a common mistake and easy to overlook
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Note that a semi-colon by itself is an empty statement. So line 11 of your code means "if command equals "Map", then do nothing" - and the block in lines 12 - 18 is completely separate from the if-statement and is always executed.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String ".equals" method always returning true?
 
Similar Threads
create a JDialog that is modal?
Program goes past where I think it should wait for Return from called program
Program wont send data through socket.
ATM machine
adding a picture