It seems to me that this if statement is not working.
I’m new in java, but i know C# and C++ pretty well, but I’ve never seen such a thing before:
today=edit[0].substring(0,10);
if (today == edit[0].substring(0,10))
{
pars_prog.addView(name_prog[i]);
}
And it doesn’t get into the IF function?
Are if statements different in Java (Android)?
When you use
==for any object references (whether strings or any other non-primitive type) it simply compares whether the references are equal – i.e. whether they refer to the exact same object, or whether they’re both null.In this case, you want to determine whether the strings are equal – i.e. whether they represent the same sequence of characters. You should use the
equalsmethod for that:However, in general when doing this you should be careful that the target of the
equalscall is non-null, or you’ll get aNullPointerException.Note that C# is similar – except that the
==operator can be overloaded, and is overloaded forstring. If the compile-time types of the operands aren’t bothstring, you’ll still get reference comparison: