Immutable Strings in Java


Strings in Java are immutable. When you manipulate a string, a new instance is created in memory.

Source Code

String greeting = "Hello";
greeting += ", World!";
System.out.println(greeting); // Outputs "Hello, World!"

Be mindful of the immutability of strings when performing extensive string manipulation, as it can impact performance due to the creation of many temporary string instances.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments