Q:

how to get the most common character in an array?

Suppose I have an integer array like this:
{5,3,5,4,2}
and I have a method which returns the most common character 
public int highestnumber(String[] num) {

        int current_number = Integer.parseInt(num[0]);
        int counter = 0;
        for (int i = 1; i < 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;
    }

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};
then the method should return 4, what should I do for this?

A:

As per what I understand your question, 
What you have to done is,
1. Create ArrayList from your int[]
2. Use HashMap for find duplicates, which one is unique
3. Sort it as Ascending order, 
4. First element is what you want..

EDIT: Answer for your question
int[] arr = {5, 4, 5, 4, 2};
ArrayList<Integer> resultArray = new ArrayList<Integer>();
Set<Integer> set = new HashSet<Integer>();

for (int i = 0; i < arr.length; i++)
    {
     if (set.contains(arr[i]))
    {
     System.out.println("Duplicate value found at index: " + i);
     System.out.println("Duplicate value: " + arr[i]);
         resultArray.add(arr[i]);
    }
    else
    {
    set.add(arr[i]);
    }
   }
Collections.sort(resultArray);

for (int i = 0; i < resultArray.size(); i++)
{
Log.e("Duplicate Values:", resultArray.get(i) + "");
}

Your need is,
int values = resultArray.get(0);

