Java Easy to understand using Comparator class
\nclass Solution {\n    HashMap<Integer, Integer> map = new HashMap<>();\n    \n    class Sorter implements Comparator<Integer>{\n\t//comparing the frequencies 
```\nclass Solution {\n    HashMap<Integer, Integer> map = new HashMap<>();\n    \n    class Sorter implements Comparator<Integer>{\n\t//comparing the frequencies \n        public int compare(Integer a, Integer b){\n            if(map.get(a) == map.get(b)){\n                return b-a;\n            }else{\n                return map.get(a) - map.get(b);\n            }\n        }\n    }\n    public int[] frequencySort(int[] nums) {\n\t//using arraylist beacuse of collection\n\t\n        ArrayList<Integer> list = new ArrayList<>();\n        for(int i=0; i<nums.length; i++){\n            list.add(nums[i]);\n            map.put(nums[i], map.getOrDefault(nums[i], 0) +1);\n        }\n        //modifying the inbuilt collection.sort to use our sorter class\n        Collections.sort(list , new Sorter());\n        \n        for(int i=0; i<list.size(); i++){\n            nums[i] = list.get(i);\n        }\n        return nums;\n    }\n}\n```
['Array', 'Java']