Kushan Athukorala wrote:Hi Pete,
a==c also returns true. To explain this we have to consider the String Constant Pool.
It is a part of memory area defined specially for Strings. Whenever you create different strings it is added to the pool but if you define same strings, it doesn't create new strings but take the string from the pool memory. So the a==c should return true in your explanation.
Kushan Athukorala wrote:
'==' is and operator in java. This operator internally use the equals() method which is defined in Object class...
Are you sure performance is the reason for that?
Kushan Athukorala wrote:. . . you are creating one . . . string in the String Constant Pool . . . This is merely because of performance reasons in java. . . .