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.  String  Immutable  Example. Reviewed by Mukesh Jha on 6:30 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.