Sorting map with value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Man4ish
    New Member
    • Mar 2008
    • 151

    Sorting map with value

    How can we sort the map with value? Generally maps are sorted by key but i need map to be sorted by value. How comparator can be used to do such thing.

    Regards
    Manish
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    You cant do that.
    Maps are sorted only by the index and max you can declare your own comparison function for sorting and that too only using the index.

    raghu

    Comment

    • Man4ish
      New Member
      • Mar 2008
      • 151

      #3
      Originally posted by gpraghuram
      You cant do that.
      Maps are sorted only by the index and max you can declare your own comparison function for sorting and that too only using the index.

      raghu
      But how this is possible since comparator function is written on the basis of key. How can we write for value?

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        If u want to use value then the value shuld be the index.
        To make clear you cant sort the map using the value.

        Raghu

        Comment

        Working...