One of the principles of Map is that the keys cannot be identical, but the task requires it. In Ideal, the code works with the same keys so that it only displays a value of several of the same keys, e. g.
Entrance:
Map<String,String> ludzie = new HashMap<>();
ludzie.put("Marcelina","Wardenga");
ludzie.put("Marcelina","Walnięta");
ludzie.put("Tomasz","Pięta");
ludzie.put("Tomasz","Pipeta");
Output:
Marcelina Walnięta
Tomasz Pipeta
Can someone explain to me why he writes all over the place that the key has to be unique, but on this assignment it turns out he doesn’t have to?
Same keys on the map
Dyskutowane
Komentarze (4)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Bob
4 lipca 2022, 11:45
when u use put(key,value) and there is already a same key in the map,it will chanage the value corresponding to that key instead of adding a new one 😁
+2
Mateusz
4 lipca 2022, 17:28
A jest sytuacja w której przy dodawaniu tego samego klucza wyskoczy błąd kodu ?
0
Bob
5 lipca 2022, 01:06
no
0
Mateusz
5 lipca 2022, 17:54
Thank you
0