Why this condition returns true, as we know == returns true if both of the variable has same reference, but here the reference is not same but still it is entering in the loop and prints Hello World.
String var1="hi";
String var2="hi";
if(var1==var2){
System.out.println("Hello World");
}
Because Java has a pool of unique interned instances, and that String literals are stored in this pool. This means that the first “hi” string literal is exactly the same String object as the second “hi” literal.