This is a very basic question regarding String.
String str1 = "abc";
String str2 = "abc";
System.out.println("out put " + str1 == str2);
I was shocked when I executed the program. I got false.
According to me, string literals are shared between the String references if another string wants to point to the same String literal. JVM will check it in String pool first and if it is not there then it will create one and give the reference, otherwise it will be shared between multiple String references like in this case (according to me).
So if I go by my theory then it should have been returning true as both the String reference point to same String literal.