posted 23 years ago
Mark,
the reason is the way java handles strings. When you create a string literal, java adds it to an internal table. Since strings are immutable, there is no need to keep multiple copies of the same data. So since you already created "hello", it is added to the table. "hello" is again looked up and found in the table when you add a reference to b. since a & b now point to the same reference to "hello", they are indeed equal. I believe that if you were to have said b = new String("hello"), then you would have received false because a new strinq object would have been created. There is a little used method on the String object called intern() which would add the value of the string object to the interal string table.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR> fantastic, a towel? <HR></BLOCKQUOTE>