Monday, 13 February 2017

string - Using "==" in Java

public class Test { 
public static void main(String[] args)
{

String s1 = "HELLO";
String s2 = "HELLO";

System.out.println(s1 == s2); // true
}
}


But when I use :




public class Test { 
public static void main(String[] args)
{
String s1 = new String("HELLO");
String s2 = new String("HELLO");

System.out.println(s1 == s2); // false
}
}



Can anybody please explain the difference here? Thankyou!

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...