Java HashMap Collections.sort() easy to understand
\nclass Solution {\n    public int[] frequencySort(int[] nums) {\n        Map<Integer, Integer> map = new HashMap<>();\n        for (int num : nums) {\n        
```\nclass Solution {\n    public int[] frequencySort(int[] nums) {\n        Map<Integer, Integer> map = new HashMap<>();\n        for (int num : nums) {\n            map.put(num, map.getOrDefault(num, 0) + 1);\n        }\n        \n        List<Integer> list = new ArrayList<>(map.keySet());\n        Collections.sort(list, (a, b) -> {\n            return (map.get(a) == map.get(b))? b - a : map.get(a) - map.get(b);\n        });\n            \n        int[] res = new int[nums.length];\n        int i = 0;\n        for (int num : list) {\n            for (int j = 0; j < map.get(num); j++) {\n                res[i++] = num;\n            }\n        }\n        return res;\n    }\n}\n```
['Java']