How do you iterate through a HashMap with the iterator object | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

How do you iterate through a HashMap with the iterator object

11th Sep 2022, 1:17 PM
Bash Athekame
Bash Athekame - avatar
2 Respuestas
+ 3
Create entrySet() then create iterator for it. HashMap hm = new HashMap() ; Iterator it = hm.entrySet().iterator(); Now it.next() returns a mapEntry() which have key, value pair. MapEntry<> e = it.next() ; e.getKey() returns key m.getValue() returns value... Hope it helps...
11th Sep 2022, 1:39 PM
Jayakrishna 🇮🇳
11th Sep 2022, 1:39 PM
SoloProg
SoloProg - avatar