+1 vote
in JAVA by
Difference between String, String Builder, and String Buffer.

String variables are stored in “constant string pool”. Once the string reference changes the old value that exists in the “constant string pool”, it cannot be erased.

Example:

String name = “book”;

Constant string pool

Constant string pool.

If the name value has changed from “book” to “pen”.

Constant string pool

Constant string pools

Then the older value retains in the constant string pool.

String Buffer:

Here string values are stored in a stack. If the values are changed then the new value replaces the older value.

The string buffer is synchronized which is thread-safe.

Performance is slower than the String Builder.

Example:

String Buffer name =”book”;

Stack

Once the name value has been changed to “pen” then the “book” is erased in the stack.

Stack1

String Builder:

This is same as String Buffer except for the String Builder which is not threaded safety that is not synchronized. So obviously performance is fast.

Related questions

+1 vote
asked May 24, 2019 in JAVA by rajeshsharma
+1 vote
asked May 24, 2019 in JAVA by rajeshsharma
...