• Post Reply Bookmark Topic Watch Topic
  • New Topic

From List to Map  RSS feed

 
Karan Kapoor Singhal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a list of Objects



I have these values in the List
employeeId - addressId
1-1
1-2
1-3
2-3
2-4
2-5

How to get all the addressIds associated to single employee into a map like ----> Map<Long,List<Long>>.


Would it be possible to retrieve values from DB as the Map above..?

i am using :


Thanks in Advance!!
 
Piet Souris
Master Rancher
Posts: 2041
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Karan,

this is straight forward to do:

It can be done via some complicated Java 8-stream, but I wouldn't adise that.

I don't know if you can get a structure like this directly out of an SQL-call.

Greetz,
Piet
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slightly shorter:
 
Karan Kapoor Singhal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Piet and Rob!!

I used Piet's logic.

Thanks again.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!