I'm having problems with an IF-statement and comparing strings. I did check this out to know more about string comparing. How do I compare strings in Java?
If I understood this right "cursor.getString(0)" will return a string. Anyway everthing in my Sqlite table is of the type "text" I guess. I can print with log.d the string "name" and that show the correct word. But when it gets to compare strings in the IF-statement it does not match anything. I have no problem with Sqlite or any other parts of the code. My if-statement does not work
Here is my code:
String Food = "Food";
while(cursor.moveToNext()){
String name = cursor.getString(0);
Log.d("name", "name: " + name); //This sprints: name: Food
if(name.equals(Food)){
// ...do something
}
else if (Food.equalsIgnoreCase(name)){
// ...do something else
}
}
It will just continue to print the rest of the column but I want to "do something" if I find a name "Food". Can someone help find out what is wrong with my IF-statement?