• Post Reply Bookmark Topic Watch Topic
  • New Topic

equals comparison should match but does not  RSS feed

 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am struggling with something that should be simple and I hope somebody here can show me the error of my ways. All I am trying to do is to make a section of code execute if two strings are equal. The two strings are userId and "A001062". When I use the debugger in Eclipse, I can see the value of userId as "A001062" but whatever string comparison I try never evaluates to true. I have tried
userId=="A001602"
userId.equals("A001602")
"A001602.equals(userId)
Assigning A001062 to a string called AAA and comparing userId to AAA

My code is as follows. I have also attached a screen shot from the Eclipse Debugger which makes me think the string comparison should succeed. I never see the debugger execute the print line nor do I see the print line on the JBOSS console.
Capture.JPG
[Thumbnail for Capture.JPG]
sample debugger screen capture
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, don't use intern(). The only thing you should need is
if( "A001062".equals( userId ) )
If that doesn't work then put the print on a separate line and set a break point there.
You could also print out what it thinks userId is.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
== is never reliable and should only be used on enum elements or when writing an equals method.
Please always tell us if you might have an answer elsewhere.
 
Michael Piaser
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved. Turns out the .equals was working but JBOSS wasn't showing the debug line on the console. When I moved the system.out.print to a separate source line, the debugger showed it executing but the JBOSS console didn't show the line. Hence, it is a different problem.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a strange problem. Thank you for telling us and well done correcting it
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!