OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Kushan Athukorala
OCPJP 6.0 [86%]
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.
Thanks,
Kushan
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Kushan Athukorala
OCPJP 6.0 [86%]
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. . . .