Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
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.

ConceptExplanation
ImmutableCannot be changed after creation
String PoolSpecial memory region for String literals
Thread-SafeNo synchronization needed for strings
PerformanceCan 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 World

String immutability का मतलब है String object को create करने के बाद उसे modify नहीं कर सकते।

Was this answer clear?