• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

is there any way to insert duplicate key in HashMap?

 
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have data which contain duplicates keys. How can i achieve this with HashMap?. is there any way?
 
Rancher
Posts: 1776
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either use Map<String,List<Object>> where the key refers to a List of values or Google Guava (I read in this thread)
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neeraj Dhiman wrote:I have data which contain duplicates keys. How can i achieve this with HashMap?. is there any way?



you can add duplicates keys but , already present value of the same key will be changed and the new value will be updated there self.
 
Marshal
Posts: 70211
280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch , somesh kanti
 
somesh kanti
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:And welcome to the Ranch , somesh kanti



Thank you Ritchie
 
somesh kanti
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use multimap instead of that one.

http://www.sgi.com/tech/stl/Multimap.html

this is the link where you can find the details about multimap.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Jai wrote:Either use Map<String,List<Object>> where the key refers to a List of values or Google Guava (I read in this thread)



good comment from the thread you directed us to, use a map<String,Set<object>> to remove real duplicates
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Wendy... you are right.
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

somesh kanti wrote:You can use multimap instead of that one.

http://www.sgi.com/tech/stl/Multimap.html

this is the link where you can find the details about multimap.


Although you're right in using a multimap (Google Guava has an implementation), are you aware that the page you linked to is about the C++ STL multimap?
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you All. Problem Solved using Map<String,List<Object>>.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic