Last active
          July 7, 2021 05:33 
        
      - 
      
 - 
        
Save cankush625/5fa4db0382468aa07745949116f4d20e to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private HashMap<Integer, Integer> sortByValueDescending(HashMap<Integer, Integer> numCounts) { | |
| List<Map.Entry<Integer, Integer> > list = | |
| new LinkedList<Map.Entry<Integer, Integer> >(numCounts.entrySet()); | |
| Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { | |
| public int compare(Map.Entry<Integer, Integer> o1, | |
| Map.Entry<Integer, Integer> o2) | |
| { | |
| return (o2.getValue()).compareTo(o1.getValue()); | |
| } | |
| }); | |
| HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); | |
| for (Map.Entry<Integer, Integer> aa : list) { | |
| temp.put(aa.getKey(), aa.getValue()); | |
| } | |
| return temp; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment