Immutable means that we can't change the content of the String once it is initialized.
1. In C++ String is Mutable . Which means you can modify the String just like array.
2. In Java String is Immutable. Which will create problems so many problems , we can resolve with the help of converting String to CharArray or Using StringBuilder .
Testing on String By Modifying It :
/**
*
*/
package com.techyield.operationsinarray;
/**
* @author satyanarayanagokavarapu
*
*/
public class StringModification {
/**
* @param args
*/
public static void main(String[] args) {
String s1 = "Sunny";
s1[4]=','; // It will show compile Time Error as This type of expression can be array type //can be resolved to String .
System.out.println(s1);
}
}
1. In C++ String is Mutable . Which means you can modify the String just like array.
2. In Java String is Immutable. Which will create problems so many problems , we can resolve with the help of converting String to CharArray or Using StringBuilder .
Testing on String By Modifying It :
/**
*
*/
package com.techyield.operationsinarray;
/**
* @author satyanarayanagokavarapu
*
*/
public class StringModification {
/**
* @param args
*/
public static void main(String[] args) {
String s1 = "Sunny";
s1[4]=','; // It will show compile Time Error as This type of expression can be array type //can be resolved to String .
System.out.println(s1);
}
}
No comments:
Post a Comment