In this code segment whenever
String s1= new String("Hello");
This statement creates a String object in the Heap Memory.
String s= "Hello";
This statement creates a String literal with value "Hello" in the String Pool. when
String s1 = "Hello";
String s= new String("Hello");
Since s1 and s are reference variables, they would be pointing at their respective memory locations so s1 points to String Pool's location and s points to Heap Memory location. Now testing if they're equal:
if(s == s1)
would return false, as the reference variables are checked. Where as
s.equals(s1)
will return true as equals function checks the individual characters in both the reference variables.