I am getting DB values with following code:
public List<String> getPlayerNames() {
List<String> playerNames = new ArrayList<String>();
c = myDataBase.rawQuery("SELECT * FROM PLAYERS",null);
while (c.moveToNext()) {
String q = c.getString(1);
playerNames.add(q);
}
c.close();
myDataBase.close();
return playerNames;
}
I now want to compare the items in this List to a String value with following method:
private boolean checkIfExists(String newPlayer) {
// TODO Auto-generated method stub
List<String> playerNames = myDbHelper.getPlayerNames();
//here a loop?!
return false;
}
But I don't really know how to compare these list items with a string value. I tried with a for loop, but then again, a list doesn't support a .length() method to go trough all elements? Tnx!
for(String playerName : playerNames){
if(playerName.equals(newPlayer)){
return true;
}
}
return false;
for (String playerName : playerNames) {
if (playerName.equals(newPlayer)) {
// do something
}
}
you might want equalsIgnoreCase() rather than equals()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With