Is String Truly Immutable?
dev.to·15h·
Discuss: DEV
Flag this post

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...