Index Page : Link
Donate : Link
Medium Link : Link
Applications : Link

String s1 = new String("code factory");
String s2 = s1.toUpperCase();
String s3 = s1.toLowerCase();
System.out.println(s1 == s2); // false
System.out.println(s1 == s3); // true

- As there is no any change in the content for s3 operation so same object value is used.
- Object is present is Heap or SCP area, rule is same.
String s1 = "code factory";
String s2 = s1.toString();
String s3 = s1.toLowerCase();
String s4 = s1.toUpperCase();
System.out.println(s1 == s2); // true
System.out.println(s1 == s3); // true
System.out.println(s1 == s4); // false

- In
s1.toString()ands1.toLowerCase()value is not changed so s2 and s3 reference to s1. - In s1.toUpperCase() value changed at runtime so it is store in Heap area.
Conclusion : Once we create an object (String), it not allow any change in that object. If we are trying to perform any changes, if there is change in the content with those changes a new object will be created. If there is no changes in the content, existing object only resused.
Whatever the existing object present in the Heap or SCP area, rule is always same.

Interesting blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple adjustements would really make my blog shine. Please let me know where you got your theme. Bless you
LikeLiked by 1 person
Thank you Ezequiel Ludovico
Please check new blog https://bit.ly/31989Yt
You’ll find best Android Apps on new blog
Download | Comment | Share
Buy Me A Coffee if you want, Find “Donate” link in Menu
LikeLike