Top k most frequent number in a stream

i have understood the concept and logic , i m using treeMap and min heap(it can also be done without min heap) , but how to get the k most occuring element from that treeMAp , i can get the highest occuring but after that i m nit able to understand it

make an array of user type like pair class which holds the integer value and its freq
sort it according to the freq and if the freq is same then according to the values

u have to implement comparable interface and have to implement the compareTo method.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.