Java offers other classes that let you really alter the contents of a String. That is the case of java.lang.StringBuffer and since JDK 1.5 there is also java.lang.StringBuilder, which is an unsynchronized, enhanded version of this latter.
I hope this helps! [ December 16, 2006: Message edited by: Edwin Dalorzo ]
It will print "Hello", not only "H". Because the String object made in the first line and reference by s is "Hello" and will never change.
If the second line was s = s.substring (0,1); the object from the first line also would not be changed. Instead a new string object would be created:"H" and the variable s would refer it. It would just print "H".
The reason why Strings is the String pool. If later in the program a String "Hello" would be used again, no new object would be created. Just the new variable would point to the already existing "Hello" object in the String pool to save resources. This pooling would not be possible, if Strings were not immutable.
all events occur in real time
The overall mission is to change the world. When you've done that, then you can read this tiny ad: