Possible Duplicate:
Java String.equals versus ==
Why when we declare string in Java we can't use == to compare this string and it will always turn to false, but if we initialize the string from the beginning it will be true?
For example :
import java.util.Scanner;
public class MyString {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String s = input.nextLine();
if(s=="Hello")
System.out.println("Hello");
String d = "Hello";
if(d=="Hello")
System.out.println("Hello");
}
}
What is the explanation for this behavior?