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?

Recommended Answers

All 2 Replies

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

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

i knew it was something like that >.<

thanks a ton

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.