0

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());

Charles
  • 50,943
  • 13
  • 104
  • 142
anindis
  • 714
  • 2
  • 11
  • 20
  • possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Simon Mar 16 '14 at 16:33
  • Please note that tags are not keywords. Stuffing the tag list full of the same words that are in your question (compare, date, string, values) will not help categorize it. Always be sure to read the descriptions that appear when selecting tags! – Charles Mar 16 '14 at 20:43

1 Answers1

3

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

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127