Interview Question

Why are Strings immutable in Java?

String operations create new values because String instances are immutable.

💡 Concept ✅ Quick Revision ☕ Java

Answer

String objects are immutable: their character sequence cannot change after construction. • Operations such as concat and replace return new strings. • Immutability allows safe sharing and stable hash values. • Security and caching can benefit, but immutability is the defined behavior rather than one single design reason.

Example

Code
String value = "Java";
value.concat(" SE");
System.out.println(value);
Output
Java

Quick Revision

String operations create new values because String instances are immutable.