As you know, Strings are objects in Java code. These objects, however, are immutable. That is, their value, once assigned, can never be changed.
Tutorial Details:
String and StringBuffer
Immutability of String objects
As you know, String s are objects in Java code. These objects, however, are immutable . That is, their value, once assigned, can never be changed.
Here the original String "Hello" is not changed. Instead, a new String is created with the value "Hello World" and assigned to the variable msg . It is important to note that though the String object is immutable, the reference variable is not.
String literals
In Java code, the String literals are kept in a memory pool for efficient use.
If you construct two String s using the same String literal without the new keyword, then only one String object is created.
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: Java General Java String and StringBuffer Tutorial
View Tutorial: Java General Java String and StringBuffer Tutorial
Related
Tutorials:
|