Category:
JAVA STRING INTERVIEW QUESTIONS AND ANSWERS
Answer:
A String object is immutable means its value cannot be changed after creation , whereas StringBuffer object is mutable , which means it’s characters or length can be changed directly without creating new memory objects .
String uses the String Constant Pool for memory allocation , whereas StringBuffer directly use Heap Memory for memory allocation .
String is Thread-safe due to immutability , whereas StringBuffer is Thread-safe due to synchronized methods .
In String class, equals() method is overriden to compare values, whereas in StringBuffer, equals() method is not overriden
