String s = new String("abcd");
There's one string in the intern pool, which will be reused every time you run the code.
Then there's the extra string which is constructed each time you run that line. So for example:
for (int i = 0; i < 10; i++) {
String s = new String("abcd");
}
will end up with 11 strings with the contents "abcd" in memory - the interned one and 10 copies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With