Hashmap and arraylist | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita

Hashmap and arraylist

How do I add an arraylist to a hashmap in java when the key is name of the objects in arraylist?

25th Jul 2020, 11:02 AM
1 Respuesta
+ 1
if class Obj has String name; field then for (Obj o : array) map.put(o.name, o); //or array.forEach(o -> map.put(o.name, o) );
25th Jul 2020, 3:35 PM