Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Java in General and the fly likes Map with duplicate keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Map with duplicate keys" Watch "Map with duplicate keys" New topic

Map with duplicate keys

Ria Mathur

Joined: Oct 11, 2001
Posts: 14
Is there a Map implementation that allows duplicate keys? I wand to use it for storing parameters and their values, and some parameters can have same names.

John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
A map cannot contain duplicate keys: Each key can map to at most one value.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
I answered this here
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You could make the data portion a List and store multiple entries that way. If the Map already contains a key then you could simply add the additional String to the List.
[smilies inserted by Beth(me!)]
[ May 29, 2003: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
here is another link. it is about c++, but the idea should remain the same.
Have you tried LearnNowOnline?
subject: Map with duplicate keys