Finding the Intersection of Arrays I would like any advice on how to improve this code. To clarify what this code considers an intersection to be, the intersection of [3,3,4,6,7] and [3,3,3,6,7] is [3,6,7]. I would appreciate any improvements to make the code more readable or perform faster.

public ArrayList&lt;Integer&gt; findIt (int[] a, int[] b){
    ArrayList&lt;Integer&gt; result = new ArrayList&lt;Integer&gt;();
    Arrays.sort(a);
    Arrays.sort(b);
    int i = 0;
    int j = 0;
    while(i &lt; a.length &amp;&amp; j &lt; b.length){
        if(a[i]&lt;b[j])
            ++i;
        else if (a[i] &gt; b[j])
            ++j;
        else{
            if (!result.contains(a[i]))
                result.add(a[i]);
            ++i;
            ++j;
        }   
    }
    return result;
}
Algorithm

You're using a O(n log(n)) algorithm here, which could be O(n²) for difficult cases since contains() is O(n) and is called in a loop. Instead, use the property of HashSet: access is O(1), which means you can achieve this in O(n) time. My algorithm below simply keeps track of what it can add to the result. I can add everything that exists in the first list, but I should not add an item I already added.

See my tested code for my implementation:

public static List&lt;Integer&gt; intersection(List&lt;Integer&gt; a, List&lt;Integer&gt; b){
    Set&lt;Integer&gt; canAdd = new HashSet&lt;Integer&gt;(a);
    List&lt;Integer&gt; result = new ArrayList&lt;Integer&gt;();

    for (int n: b) {
        if(first.contains(n)) {
            result.add(n);
            // we wish to add only one n
            canAdd.remove(n);
        }
    }

    return result;
}


Comments on your code


You should return a List, not an ArrayList since it's an implementation detail. Using an ArrayList is OK here since adding at the end of it has O(1) amortized complexity. Otherwise, lists should be LinkedList (when adding to the beginning, not to the end, as @Landei points out).
Be careful about the names you choose. findIt doesn't seem to be appropriate, but removeDuplicates or intersection describes what the code does.