Originally posted by Shiva Mohan:
Hi again,
The above one,
" String ".trim()=="String" returns false.Becuase both Strings are not in the same stringpool.Like this
I thought
"String".repace('g','g')=="String" ---->After replace the origianl g with another g.That string is in differnent place and the RHS String is in diffenrent place.so both referes to the different object and thought it would retuurn false.
But "String".repace('g','g')=="String" returns true.How come Both String are in the same stringpool.In other words,both references refer to the same object?
replace
public String replace(CharSequence target,
CharSequence replacement)Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.
public interface CharSequence
This interface does not refine the general contracts of the equals and hashCode methods. The result of comparing two objects that implement CharSequence is therefore, in general, undefined. Each object may be implemented by a different class, and there is no guarantee that each class will be capable of testing its instances for equality with those of the other
SCJP 1.4 85%
But "String".repace('g','g')=="String" returns true.How come Both String are in the same stringpool.In other words,both references refer to the same object?
SCJP 1.4 85%