Originally posted by mark stone:
mike, as i see it now s1,s2,s3 are all pointing to the same object. (all == amongst the 3 references would be true)
Right. I wasn't really questioning that. I was wondering
which object they now point to --or, in other words, whether the string in the pool (that all 3 references now point to) after interning is the one that was there before or the newly created one.
Just checked the API for intern(), which seems to imply that the old one stays in the pool and the new one gets discarded:
When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.