I am learning string implementations in java, got the following doubt while learning
String s1 = "name1";
String s2 = "name1"; // both strings having same value;
I know that,
s1==s2
above comparison will return false (based on what i studied, == compares the memory location of the string objects).
but this returns true;
- I want to know the reason why its returning 'true'?
- Also how the memory will be allocated for a string literal in string pool(what really happens inside the string pool/back end);
for the following operations,
String s1 = "String1";
String s2 = s1+"xyz";
String s3 = s1.replace("i","o");