'Multimodal values in java

I am trying to make a program that will find the mode of a random array. So far I have got it to find the mode of one set of numbers, although my code does not work for when the array comes up with more than one mode. I am using HashMap by the way. Here is my code:

for(int i = 0; i < arr.length; i++) {

        if (hm.get(arr[i]) != null) {

            int count = hm.get(arr[i]);
            count++;
            hm.put(arr[i], count);

            if(count > max) {
                max  = count;
                temp = arr[i];
            }

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source