Sunday, 6 May 2018

how java string immutable?

I have a string in method in java class as below




public void show(){
String s1;
s1 = "abc";
s1 = "def";
System.out.println(s1);
}


Here the output is def, but as String is immutable so I don't understand how string s1 is immutable here as I can change the String s1 content from abc to def.




Could you please make me understand this?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...