Thursday, November 8, 2018

string - Using "==" in Java

Answer



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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...