This is mallikarjuna Reddy. My HashMap having key based values. some times values may be duplicate. so need to sort HashMap in the desc order. please help me in this problem.
posted 10 years ago
You should use a TreeMap for sorting purpose. By default it is sorted by natural-order (i.e. using the compareTo method). You could also add a Comparator to have a better control over your sorting. Checkout the TreeMap API. Example:
You could also pass your existing HashMap as an argument.