Found this solution to make this method:
int[] withoutDuplicates(int[] a){
int n = a.length;
   if (n < 2) {
        return a; 
    }
    for (int i = 0; i < n-1; i++) { 
         for (int j = i+1; j < n; j++) {
               if (a[j] == a[i]) {
                 --n;
                 System.arraycopy(a, j+1, a, j, n-j);
                --j; 
             }//end if
        } //end for
     }//end for
     int[] aa = new int[n]; 
     System.arraycopy(a, 0, aa, 0, n); 
     return aa;
}//end method
I do not understand why it is using an array of length n. Shouldn't it be of size n minus the number of duplicates erased? Is this the most optimal way of implementing the method? or is there any java resource I could use?
 
     
    