Is String Truly Immutable?
dev.to·12w·
Discuss: DEV

Okay, the title might or might not be clickbait. The original article is here, you can check it for yourself.

Or if you don’t want to, you can view this short by Jose Paumard:

TL;DR

Here is your poison:

String is technically mutable, but effectively immutable

Long Answer (Sorry Jose, Let Me Steal Your Catchphrase)

Examining the String class, we will immediately see these fields:

private final byte[] value; // Actual holder of String value
private final byte coder; // either LATIN (0) or UTF16 (1)

private int hash;
private boolean hashIsZero;

If you still use JDK 8 and below (why would you?), you will see this instead:

private final char[] value;

private int hash;

Do you see somet…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help