I'm writing an app for Android. I use a string array to pull all player names from shared preferences (has to be a string array). I have a list to pull all active players from shared preferences (has to be a list). I need to check my list to see if it contains any players that are not in my player's array and delete them. I just can't seem to figure out the logic.
For example:
List contains: b c a e
Array contains: a b c d
Since 'e' exists in List but not in Array, 'e' needs to be removed from the list. I know the commands (.contains(), .remove(), for()), I just can't figure out the logic.
My first attempt was:
for(int x=0;x<numOfPlayers;x++){
players[x] = getPrefs.getString("player"+Integer.toString(x), " ");
if(activePlayers.size()>0)
if(activePlayers.contains(players[x]))
playersChecked[x] = true;
else{
if(x<activePlayers.size())
activePlayers.remove(x);
}
}
But this removes x from activePlayers if player[x] has an item that activePlayers doesn't, which is fine. It needs to be the other way around.