Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map that contains duplicates ?

Status
Not open for further replies.
May 13, 2002
75
GB
Is there a class similar to a Map that will allow you to add items with duplicate keys ?

I have a list objects with a rating value (key) that i want to store in an object in a sorted order. Any ideas ?

Thanks

Alistair

Alistair [monkey]
 
Both "Set"s and "Map"s can NOT contain duplicates.
A (some) "List"s can contain duplicates, but you have to do the sorting yourself.

A NON-performant solution would be to use a (Sorted)Set or a (Sorted)Map, but have only one entry per key, and use a Vector as the object to be stored.

Maybe somebody else has a better solution ?
 
How about creating a new class with 2 fields, value and rating, and inserting the objects into an array?
 
If i did them in an array i would have to implement sorting myself (which i'm trying to avoid). I've tried hologram's Vector in a sorted Map suggestion which made for some interesting loop code but seems to work ok.

Cheers

Alistair [monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top