```
class Solution {
public int[] singleNumber(int[] nums) {
Arrays.sort(nums);
int index= 0;
int[] newArr = new int[2];
for(int i=0;i<nums.length-1;){
if(nums[i] == nums[i+1]){
i = i+2;
}else{
newArr[index] = nums[i];
index++;
i++;
}
}
if(index==1){
newArr[index]=nums[nums.length-1];
}
return newArr;
}
}
```