Immutable string:
Immutable string means no-changeable after manipulating in the program.
Program code:
public class HelloWorld{public static void main(String args[]){
String s="Heera";
s.concat("Babu");//concat() method appends the string at the end
System.out.println(s);
}
}
Sample Output:
Since, Here two objects are created but s reference variable, therefore use reference variable assignment.
if further code is changes as:
public class HelloWorld{
public static void main(String args[]){
String s="Heera";
s=s.concat("Babu");//concat() method appends the string at the end
System.out.println(s);
}
}
then output:
Tags:
java programming