[Java] Simple Custom Sort with Detailed Explanation!
\npublic int[] frequencySort(int[] nums) {\n\tMap<Integer, Integer> map = new HashMap<>();\n\t// count frequency of each number\n\tArrays.stream(nums).forEach(n
```\npublic int[] frequencySort(int[] nums) {\n\tMap<Integer, Integer> map = new HashMap<>();\n\t// count frequency of each number\n\tArrays.stream(nums).forEach(n -> map.put(n, map.getOrDefault(n, 0) + 1));\n\t// custom sort\n\treturn Arrays.stream(nums).boxed()\n\t\t\t.sorted((a,b) -> map.get(a) != map.get(b) ? map.get(a) - map.get(b) : b - a)\n\t\t\t.mapToInt(n -> n)\n\t\t\t.toArray();\n}\n```\n\ncustom sort explanation:\n**.stream(nums)**\niterates through the nums array\n\n**.boxed()**\nconverts each int to Integer object, this is because .sorted() can only operate on objects\n\n**.sorted((a,b) -> map.get(a) != map.get(b) ? map.get(a) - map.get(b) : b - a)**\nif frequency of two numbers are not the same, sort by ascending frequency. If frequencies are the same, sort by decending numeric value\n\n**.mapToInt(n -> n)**\nconverts Integer to int\n\n**.toArray()**\nreturns array
['Sorting', 'Java']