I have a hashmap of nobel winners from 1993 - 2009, the key is the year and the value is an array of string of the winners names. Some years have more than one winner and no year has more than 3. I am trying a method to remove a specific name from the hashmap and to remove the key if there is only one winner for that specific year. When I try this method it removes the entire key and value, no matter if there were more than one winner in that year. (example in 1993 the winners are Nelson Mandela and Frederik Willem de Klerk, if i try to remove only Nelson Mandela, the entire entry from 1993 is gone)
public void removeWinner(String nameOfWinnerToRemove)
{Iterator <HashMap.Entry<Integer, String[]>> it = winners.entrySet().iterator();
while(it.hasNext())
{
HashMap.Entry<Integer, String[]> entry = it.next();
for(int i = 0; i < entry.getValue().length; i++)
{
if(entry.getValue()[i].equalsIgnoreCase(nameOfWinnerToRemove))
{
it.remove();
}
}
}
}