Table Of Content

Introduction To Strings

Types Of String

1. Immutable String

String s = new String("Nandan");
String s = "Nandan";
char []a ={a,b,c,d};
byte[] a={97,98,99,100};

2. Mutable String

public class MutableString
{
    public static void main (String[] args)
    {
        StringBuffer str1 = new StringBuffer("JavaGoal");
        StringBuilder str2 = new StringBuilder("Learning");
        
        System.out.println("Value of str1 before change :" + str1);
        System.out.println("Value of str2 before change :" + str2);
        
        str1.append(".com");
        str2.append(" website");
        
        System.out.println("Value of str1 after change :" + str1);
        System.out.println("Value of str2 after change :" + str2);
    }
}
//output
Value of str1 before change :JavaGoal
Value of str2 before change :Learning
Value of str1 after change :JavaGoal.com
Value of str2 after change :Learning website

Note

Immutable String