View Single Post
  #2 (permalink)  
Old 05-19-2007, 02:49 PM
fritz fritz is offline
Member
 
Join Date: May 2007
Posts: 5
fritz is on a distinguished road
because you are not changing the String, you are changing what the 's' reference points to.

in other words, 's' is NOT a String, it is a REFERENCE TO a String. 's' lives on the stack, and the String object containing "abcde" lives in the heap (let's not get into the String pool right now). when you run the line

s= "12345", a new String is created in the heap. 's' is changed to point to it, but the String "abcde" is still hanging around, unchanged.
Reply With Quote