Java XOR for an array : I'm trying to XOR an array of numbers all at once in Java. the array size is determined at the start of the program by the user and so has no limit. I thought of doing it this way but realised that it would not work.

    static void cpuTurn(int[] nimArray){
        int[] val = new int[nimArray.length];
        int holding = 0;

        for (int i = 0; i < nimArray.length; i++) {
            holding = holding^nimArray[i];
        }
    }

For example an array as such {4,5,6} should return 3 but as it stands, my code returns 7