0

hello, i have made the code below. however, when comparing the two strings they are not equal when in theory i thought they would be.

 String word="abc";
        String d="";
        d += "a";
        d += "b";
        d+= "c";
        if(word==d)
{
System.out.println("IS EQUAL");
}

When i just print out string d it prints out abc, but for some reason its not REALLY abc. why?

2
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by eikal
1

You're comparing references of string objects. Use String.equals() method to compare strings:

if(word.equals(d))
  //
else
 //
0

i knew it was something like that >.<

thanks a ton

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.