String Immutable Example.
Here is example how String is immutable . If you check the code properly you can
remove your confusion .
package Java8;
/** @auther-Mukesh Jha */
public class StringImmutable {
public static void main(String[] args) {
testmethod();
}
private static void testmethod() {
String s2="String";
System.out.println("s2-->"+ s2);
System.out.println("s2 address-->"+s2.hashCode());
s2 = "another referce";
System.out.println("s 2-->"+s2);
System.out.println("s2 address-->"+s2.hashCode());
s2.concat("pool") ; // String immutable example
System.out.println(s2);
s2.substring(0,3);
System.out.println(s2); // String immutable example
}
}
String Immutable Example.
Reviewed by Mukesh Jha
on
6:30 AM
Rating:
No comments:
Add your comment