Find all single elements in an array I am interested in printing all numbers that do not have a match in an array.
Example: 1,3,4,5,3,4,5,5,6 result 1,5,6
Please review my solution bellow. What would be a much better way for this? Any input on how to improve this is welcome

public static Integer[] outputSinglePair(Integer[] numbers){  
        if(numbers == null)  
            throw new IllegalArgumentException();  

        Arrays.sort(numbers);  
        ArrayList&lt;Integer&gt; result = new ArrayList&lt;Integer&gt;();  
        for(int i = 0; i &lt; numbers.length - 1; ){  
            if(numbers[i] != numbers[i + 1]){  
                result.add(numbers[i]);  
                i++;                
            }     
            else  
                i+=2;  
            if(i == numbers.length - 1)result.add(numbers[i]);//we hit last element of array which is unpaired
        }  
        return result.toArray(new Integer[0]);  
    }
I think this is the sort of thing for which HashSet is perfect. Your implementation would look something like I have shown below. The advantage is that you don't need a sort so your running time is strictly linear.

(Updated to fix syntax errors)

public static Integer[] outputSinglePair(Integer[] numbers){  
    if(numbers == null)
        throw new IllegalArgumentException();

    HashSet&lt;Integer&gt; result = new HashSet&lt;Integer&gt;();
    for (int next: numbers) {
        if (result.contains(next)) {
            result.remove(next);
        }
        else {
            result.add(next);
        }
    }
    return result.toArray(new Integer[result.size()]);
}