Thursday, 1 December 2016

String comparison in Java




I am working with Java code in JSP and I am trying to compare strings and I am having problem with that.



I have declared two strings



s1 = "din";
s2 = "din";



However, the if (s1 == s2) never executes. Can someone help me?


Answer



You use 'equals' when you compare strings.



if(s1.equals(s2)) { true }


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