Results 1 to 4 of 4
  1. #1
    jepoys1 is offline Member
    Join Date
    Apr 2017
    Posts
    5
    Rep Power
    0

    Question How to compare duplicates in a map

    I am stuck on how to compare keys and values from a map.
    I have a Hashtable<Integer, Integer> containing values. For example, i want to find {4,1} and {1,4} so I can delete any of them in the list.
    Here is what I have so far and I really do apologize for the lack of my ability to express my problem more in words as I am stuck.

    How to compare duplicates in a map-myprob.png

    I hope I can get help. Thank you in advance

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: How to compare duplicates in a map

    how to compare keys and values from a map.
    Look at the API doc for MAP. There are methods that can be used to get a Set of the values in the Map. For example keySet.
    Use its contents to access the values in the Map.

    Note: Images are not good because text can not be copied from them to include in a response and they can't be searched.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to compare duplicates in a map

    Seems to me that if a key points to a value and that value (when used as a key) points to the previous key, you have a duplicate pair.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How to compare duplicates in a map

    Just a note.
    You should be using HashMap, not Hashtable. The one you're using was essentially replaced.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replace duplicates
    By dibs in forum New To Java
    Replies: 3
    Last Post: 12-08-2015, 08:57 PM
  2. Removing Duplicates.
    By dashwall in forum New To Java
    Replies: 9
    Last Post: 12-29-2009, 01:03 PM
  3. Duplicates in more than two sets
    By JavaJ in forum New To Java
    Replies: 8
    Last Post: 12-03-2009, 04:07 PM
  4. Duplicates
    By Gambit17 in forum New To Java
    Replies: 5
    Last Post: 11-08-2007, 09:56 AM
  5. duplicates in iReport
    By Heather in forum Advanced Java
    Replies: 1
    Last Post: 07-05-2007, 04:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •