Java manages a String Pool. when you initialize a string as
String n = "hai";
it will be stored in String pool.
But if the statement is
String n = new String("hai");
it will be in heap.
so the location is different but the content is same.
So .equals() method checks the content while == looks for the location