Finding unpaired number in an odd length Array of integers codility OddOccurrencesInArray:

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.
For example, in array A such that:
  A[0] = 9  A[1] = 3  A[2] = 9
  A[3] = 3  A[4] = 9  A[5] = 7  A[6] = 9
    • the elements at indexes 0 and 2 have value 9,
    • the elements at indexes 1 and 3 have value 3,
    • the elements at indexes 4 and 6 have value 9,
    • the element at index 5 has value 7 and is unpaired.
Write a function:
     class Solution { public int solution(int[] A); }
that, given an array A consisting of N integers fulfilling the above conditions,
returns the value of the unpaired element.

class Solution {

    public int solution(int[] A) {
       
        final int len = A.length;
        
        Arrays.sort(A);
        
        for (int i = 0; i &lt; len ;) {
            int counter = 1;
            int current = A[i];
          
            while ((i &lt; len - 1) &amp;&amp; (current == A[++i])) {
                counter++;
            }     
            
            if (counter % 2 == 1) {
                return current;
            }
        }
        return -1;
    }
}

Could this code be bettered in terms of time complexity or code quality?
Sorting of the array will take O(n (log n)) in the average case. You can do it in linear time using bitwise operation

public class Test {
    public static void main(){
        int a = 0;
        int[] arr = {9,3,9,3,9,7,9};

        for (int i = 0; i &lt; arr.length; i++ ){
            a = a ^ arr[i];
        }

        System.out.println(a);
    }
}


Any number which will XOR with 0 will be the number itself. But if it will XOR with itself, it will be 0. In the end, we'll get the non paired number.