Group Objects by Common Key
Posted
by Marshmellow1328
on Stack Overflow
See other posts from Stack Overflow
or by Marshmellow1328
Published on 2010-04-07T14:49:41Z
Indexed on
2010/04/07
14:53 UTC
Read the original article
Hit count: 155
I have a list of Customers. Each customer has an address and some customers may actually have the same address. My ultimate goal is to group customers based on their address. I figure I could either put the customers in some sort of list-based structure and sort on the addresses, or I could drop the objects into some sort of map that allows multiple values per key.
I will now make a pretty picture:
List:
A1 - C1, A1 - C2, A2 - C3, A3 - C4, A3 - C5
Map:
A1 A2 A3
C1 C3 C4
C2 C5
Which option (or any others) do you see as the best solution? Are there any existing classes that will make development easier?
© Stack Overflow or respective owner