Where is the problem ?
package fr.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
/*
Nous n'avons pas besoin de répétitions
*/
public class Solution {
public static HashMap<String, String> creerMap() {
HashMap<String, String> map = new HashMap<>();
map.put("Duroc", "théo");
map.put("Vigne", "théo");
map.put("Lemahieu", "fabrice");
map.put("Canet", "fabrice");
map.put("Perrin", "Christian");
map.put("Shwab", "Lisa");
map.put("Diawara", "Fatim");
map.put("Bouyeyia", "Meissan");
map.put("Gauthier", "Arnaud");
map.put("Mehus","Thomas");
return map;
}
public static void supprimerPrenonsIdentiques(Map<String, String> map) {
HashMap<String, String> copie = new HashMap<>(map);
int compte = 0;
for (String prenomCopie : copie.values()) {
for (String prenom : map.values()) {
if (prenom.equals(prenomCopie)) {
compte++;
}
}
if (compte > 1) {
supprimerElementMapParValeur(map, prenomCopie);
compte = 0;
}
}
}
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) {
}
}