key value list sorting based on same key if found more then once

Discussion in 'C#' started by sam1789, Mar 20, 2024.

  1. #1
    Hello i need one help i am thinking to store values in (key,pair) where key is a double array of 4 values. finaly I have to sort this list based on double value (key) if i find more then one key i have to store those values say ex (a,1) (b,2) (a,2) (c,1) In tis case i am looking for sorted list to have only (a,1) & (a,2). ANy help appreciated
     
    sam1789, Mar 20, 2024 IP
  2. GreenHost.Cloud

    GreenHost.Cloud Active Member

    Messages:
    471
    Likes Received:
    34
    Best Answers:
    3
    Trophy Points:
    73
    #2
    You can use a TreeMap with a custom Comparator to sort based on the double value in the key. Then, remove duplicate keys by using a HashSet to store unique keys. Finally, convert the TreeMap keys back to the desired (key, pair) format.
     
    GreenHost.Cloud, Jul 1, 2024 IP