Possible Duplicate:
String comparison and String interning in Java
I try to run the following code in java:
if("hello".trim() == "hello".trim())
System.out.println("Equal");
else
System.out.println("Not Equal");
and it prints Equal. I understand in this case both strings have same reference. But When I try the same by just adding a space in both strings, it prints "Not Equal".
if("hello ".trim() == "hello ".trim())
System.out.println("Equal");
else
System.out.println("Not Equal");
Can anyone explain why I am getting "Not Equal"...?