anindis
anindis

Reputation: 724

Comparing Two String\Date Variables

I have this code.

 for (j=0; j<st.length; j++)
        { Log.d("MY LOGGGGS", "Цикл "+j);
        if (st[j]==compdate)
         { Log.d("MY LOGGGGS", "Даты совпали");}
           else 
       { Log.d("MY LOGGGGS", "Даты не равны:"+compdate+"===="+st[j]+"=");}}

And that's what my logs are showing.

enter image description here

As you can see, the string values in "st" are the same as the value in "compdate", but "if" doesn't work right. No excess spaces. The same thing happens when I'm converting these values to date and try to compare. What can I do wrong?

P.S. st is {"2014-03-16","2014-03-16"}; compdate is currentdate; String compdate=(String) DateFormat.format("yyyy-MM-dd",new Date());

Upvotes: 0

Views: 72

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93726

Always use string.equals() to compare strings. == only checks if they're the same reference, not if their contents are identical.

Upvotes: 3

Related Questions