This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
Bartender

Joined: Aug 16, 2005
Posts: 12921
    
    3

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: String ".equals" method always returning true?
 
Similar Threads
adding a picture
Program goes past where I think it should wait for Return from called program
ATM machine
Program wont send data through socket.
create a JDialog that is modal?