Je suis bloquée avec en plus une concurrentModificationException et je ne sais pas comment l'éviter.
Quelqu'un pourrait il m'aider?
package fr.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
/*
Nous n'avons pas besoin de répétitions
*/
public class Solution {
public static HashMap<String, String> creerMap() {
//écris ton code ici
HashMap <String, String> identite = new HashMap<>();
identite.put("Lounes","Lilas");
identite.put("Kharbine","Luc");
identite.put("Poro","Jeanne");
identite.put("Jeannelle","Ludovic");
identite.put("Panco","Thierry");
identite.put("Sirop","Marie");
identite.put("Fillo","Lilas");
identite.put("Marcol","Therese");
identite.put("Filibert","Jean");
identite.put("Roche","Paul");
return identite;
}
public static void supprimerPrenomsIdentiques(Map<String, String> map) {
//écris ton code ici
HashMap<String, String> mapTemp = new HashMap<>(map);
for(Map.Entry<String, String> entry : mapTemp.entrySet()){
//String valeur = map.keySet();
Iterator it = map.entrySet().iterator();
for(Map.Entry<String, String> personne : map.entrySet())
{
if(entry.getValue().equals(personne.getValue())) {
supprimerElementMapParValeur(map,personne.getValue());
}
}
}
/*map.forEach((k,v) -> System.out.println("Key = "
+ k + ", Value = " + v)); */
}
public static void supprimerElementMapParValeur(Map<String, String> map, String valeur) {
HashMap<String, String> copie = new HashMap<String, String>(map);
for (Map.Entry<String, String> paire : copie.entrySet()) {
if (paire.getValue().equals(valeur))
map.remove(paire.getKey());
}
}
public static void main(String[] args) {
}
}