• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Problem

 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..all
I am compiling and executing a simple String program on JDK 1.5
my code is....



its out put is :
str1.equals(str2):true
false

but I am expecting

str1.equals(str2):true
str1==str2 :false

why does str1==str2 : is disappeared in outout


help me out please.

Thanks
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is that + has higher precedence than ==, so the String concatenation is performed first, and then the resulting String is compared with == to str2.

Also I would expect that when you fix the String concatenation problem, you won't get a false in the second statement.
[ August 13, 2006: Message edited by: Keith Lynn ]
 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh!!! Keith great
thanks for your valuabe suggesion

I solve it by using

now it show ing perfect.....

 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly the same problem is described here:
http://jqa.tmorris.net/GetQAndA.action?qids=9
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic