Thursday, August 2, 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

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