This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Problem" Watch "String Problem" New topic

String Problem

Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
I am compiling and executing a simple String program on JDK 1.5
my code is....

its out put is :

but I am expecting

str1==str2 :false

why does str1==str2 : is disappeared in outout

help me out please.

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Jul 24, 2003
Posts: 260
oh!!! Keith great
thanks for your valuabe suggesion

I solve it by using

now it show ing perfect.....

Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Exactly the same problem is described here:

Tony Morris
Java Q&A (FAQ, Trivia)
I agree. Here's the link:
subject: String Problem
Similar Threads
Problem on String
Difference between '==' & equals()
Referencing to another object
String handling.
Can anyone explain what is == and equal( ) ?