Hashmap and arraylist | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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
Zahra
1 Answer
+ 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
zemiak