How is it possible for two String objects with identical values not to be equal under the == operator?

The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.

Showing Answers 1 - 1 of 1 Answers

lwpro2

  • Mar 13th, 2011
 

Normally, when define a string instance, if using, String s = "ABC"; the existing string variable at the string pool is returned.
However, if using new String("ABC") there is always one additional String object created. Besides, the new String() object is != "ABC", however, using equals, it return true.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions