Thursday 2 August 2018

String comparison in Java: what is wrong with "=="?








public class S_eaqual {
public static void main(String[] args) {
String s1 = "one", s2 = "two";
if (s1 + s2 == "onetwo") {
System.out.println("Yes..equal");
}
}
}



This type of comparison shows errors. Is this not the right way of comparing strings?
Two String objects can be compared using == operator. So why this is showing error?

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...