Tuesday 5 November 2019

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...