Find The Parity Outlier I am trying to solve this coding exercise:

You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns N.
For example:
[2, 4, 0, 100, 4, 11, 2602, 36]
Should return: 11
[160, 3, 1719, 19, 11, 13, -21]
Should return: 160

Here is my code:
import java.util.ArrayList;
public class FindOutLier {
    public static int search(ArrayList&lt;Integer&gt; lists, int num) {
        int count = 0;
        int index;
        Integer a[] = new Integer[lists.size()];
        a = lists.toArray(a);
        for (index = 0; index &lt; a.length; index++) {
            if (num == a[index]) {
                count++;
            }
        }
        return count;
    }

    public static boolean checkEvenOrOdd(int[] integers) {
        int t = 0;
        double result = 0.0;
        ArrayList&lt;Integer&gt; l = new ArrayList&lt;Integer&gt;(integers.length);
        while (t &lt; integers.length) {
            result = integers[t] % 2;
            if (result == 0.0) {
                l.add(1);
                t++;
            } else {
                l.add(0);
                t++;
            }
        }
        int counter = search(l, 1);
        if (counter == 1)
            return true;
        else
            return false;
    }

    public static int find(int[] integers) {
        int t = 0;
        double newresult = 0.0;
        boolean result = checkEvenOrOdd(integers);
        if (result == false) //
        {
            while (t &lt; integers.length) {
                newresult = integers[t] % 2;
                if (newresult != 0.0) {
                    break;
                } else {
                    t++;
                }
            }
        } else {
            while (t &lt; integers.length) {
                newresult = integers[t] % 2;
                if (newresult == 0.0) {
                    break;
                } else {
                    t++;
                }
            }
        }
        return integers[t--];
    }
}

It passed Junit Test in Eclipse. Please review it/ suggest any improvements.
Thanks.
Your approach is far too complicated.


In checkEvenOrOdd() you create a ArrayList&lt;Integer&gt; containing
zeros or ones.
In search() you create an Integer a[] from that list.
Then you iterate over the array and count the number of zeros or ones.


You can iterate over int[] integers directly to find the number of odd (or even) entries:

    int oddCount = 0;
    for (int n : integers) {
        if (n % 2 != 0) {
            oddCount += 1;
        }
    }


Note how a "enhanced for statement" can be used to iterate over
the array elements, instead of a for-loop or a while-statement for
the array indices, as in your code.

There is also no need to use a double result or floating point literals
when doing an integer remainder calculation. 

    if (counter == 1)
        return true;
    else
        return false;


can be simplified to

    return (counter == 1)


But in this case the entire logic can be put into a single function,
e.g. like this:

public static int find(int[] integers) {

    int oddCount = 0;
    for (int n : integers) {
        if (n % 2 != 0) {
            oddCount += 1;
        }
    }

    if (oddCount == 1) {
        for (int n : integers) {
            if (n % 2 != 0) {
                return n;
            }
        }
    } else {
        for (int n : integers) {
            if (n % 2 == 0) {
                return n;
            }
        }
    }
    return 0;
}


Then one could try to avoid the code repetition for the even/odd
case.

But actually I would suggest a completely different, more efficient  approach:


Check the first two array elements if they are even or odd.
If they are both even, the outlier can be found
by search for the first odd element, starting at index 2.
If they are both odd, the outlier must be even, and can be found
similarly.
If the first two array elements have different parity, one of 
them is the outlier. Which one, can be determined by checking the third
array element.