Showing posts with label String literals. Show all posts
Showing posts with label String literals. Show all posts

Wednesday, 1 February 2012

String and StringBuffer

Immutability of String objects


As you know, Strings are objects in Java code. These objects, however, are immutable. That is, their value, once assigned, can never be changed. For instance:

String msg = "Hello";
msg += " World";


Here the original String "Hello" is not changed. Instead, a new String is created with the value "Hello World" and assigned to the variable