Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to check duplicates in hashmap

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
Iam using multimap to store duplicates ,for each key multiple values,
but how to retrive it means how to check for duplicate values while retrieving.please tell me how to check duplicate values.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The keys for a HashMap are stored in a Set - it won't allow duplicates. Either way, you can use the containsKey or containsValue method to look for anexisting record before insertion.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an intermediate question, probably, but strikes me as belonging in advanced because complexity is involved.

MultiMap maps a key to a List or Vector which would mean that you would call get Iterator on the the return from a key lookup. You would then have to walk the value with the iterator, counting and testing and so on. I don't see where an Iterator is going to give out a count(), accessing the list or vector before walking the iterator would tell how many elements are in the List or Vector
 
vin Hari
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you,
For reply, but iam not checking for duplicates while inserting,Actually what iam trying is iam creating menu driven program for which it requires for single submenu can contain many many elements thats why iam using multi map to insert but while retriving there values i want to check if next key is similar to previous key then make it as submenu and take out only values which form a items of submenu for that i require to see for duplicates even i tried with hashcode() but i did not get,
any more solutions please.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us a little code that almost works? Then we can tell exactly where you're stuck.

Is there something like this?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic