Consider the following example. String str = new String(); str = "Hello"; System.out.println(str); //Prints Hello str = "Help!"; System.out.println(str); //Prints Help! Now, in Java, String objects are immutable. Then...
  • May 25, 2022
  • 0 Comments
We all know that String is immutable in Java, but check the following code: String s1 = "Hello World"; String s2 = "Hello World"; String s3 = s1.substring(6); System.out.println(s1);...
  • May 8, 2022
  • 0 Comments
This could be the dumbest question ever asked but I think it is quite confusing for a Java newbie. Can somebody clarify what is meant by immutable? Why is...
  • May 7, 2022
  • 0 Comments
Following the discussions here on SO I already read several times the remark that mutable structs are “evil” (like in the answer to this question). What’s the actual problem...
  • May 2, 2022
  • 0 Comments