title: Best implementation to remove duplicates JAVA array
body: <p>Found this solution to make this method:</p>
  
  <pre><code>int[] withoutDuplicates(int[] a){
  int n = a.length;
     if (n &lt; 2) {
          return a; 
      }
      for (int i = 0; i &lt; n-1; i++) { 
           for (int j = i+1; j &lt; 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
  </code></pre>
  
  <p>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?</p>