Interview question
What is String immutability in Java? Java में String immutability क्या है?
Answer
String immutability means once a String object is created, it cannot be changed. If you modify a string, a new String object is created instead of modifying the existing one.
| Concept | Explanation |
|---|---|
| Immutable | Cannot be changed after creation |
| String Pool | Special memory region for String literals |
| Thread-Safe | No synchronization needed for strings |
| Performance | Can be cached and optimized |
String s1 = "Hello";
String s2 = s1;
String s3 = s1.concat(" World");
System.out.println(s1); // Hello
System.out.println(s3); // Hello WorldString immutability का मतलब है String object को create करने के बाद उसे modify नहीं कर सकते।
Was this answer clear?