A java string is an object of the class java.lang. Java string contains a sequence of characters.
String is immutable, means its content cannot be modified once it is created. For example, the method toUpperCase() constructs and returns a new String instead of modifying the its existing content.
Also String can be creared as:
This will create an string name with value tutorial heap.
If your program requires lot of modification in a string then it is better to use String Buffer or String Builder classes.
Creating String object
There are two ways to create a string object:
We have already seen the syntax in above two examples. Let's understand it in more detail.
It is created with the help of double quotes.
If two string literals have the same contents, they will share the same storage inside the common pool. This approach is adopted to conserve storage for frequently-used strings.
By new keyword
When a string is created by using new keyword object is created in heap memory and the literal (value) is placed in the string constant pool.