Given the List
of Person
objects of this class:
class Person(val id : Long, val name : String)
What would be a scala way to get (java) a HashMap with id
for keys and name
for values?
If the best answer does not include using .map
, give an example with it, even if it is harder to do.
Thanks.
EDIT
This is what I have right now, but it is not too immutable:
val map = new HashMap[Long, String] personList.foreach { p => map.put(p.getId, p.getName) } return map
source share