how to get the most common character in an array?
<p>Suppose I have an integer array like this:
{5,3,5,4,2}</p>

<p>and I have a method which returns the most common character </p>

<pre><code>public int highestnumber(String[] num) {

        int current_number = Integer.parseInt(num[0]);
        int counter = 0;
        for (int i = 1; i &lt; num.length; ++i) {
            if (current_number == Integer.parseInt(num[i])) {
                ++counter;

            } else if (counter == 0) {
                current_number = Integer.parseInt(num[i]);
                ++counter;

            } else {
                --counter;

            }
        }

        return current_number;
    }
</code></pre>

<p>but if I have multiple common character then i need to get the number which is closest to one(1), like if i have an array like this:
{5,5,4,4,2};</p>

<p>then the method should return 4, what should I do for this?</p>
