When comparing two strings, I was taught that we shouldn't use the logical operator (==). We should use String.equals(String) for the comparison. However, I see that the following code complies and prints "Hello Friend
" with the latest JDK(1.6_23). I tried searching around and couldn't find any reference. From when is this happening?
public class StringComp{
public static void main(String args[]){
String s = "hello";
if(s=="hello"){
System.out.println("Hello Friend");
}else{
System.out.println("No Hello");
}
}
}