String: 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
.
If the name value has changed from “book” to “pen”.
Constant string pool
Then the older value retains in the constant string pool.
String Buffer:
Example:
String Buffer name =”book”;
Once the name value has been changed to “pen” then the “book” is erased in the stack.
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.
We covered nearly 50 + primary Java interview questions in this tutorial for fresh and experienced candidates. Q.1- What is… Read More