title: Removing duplicates using collections in Java when merging two sorted arrays
body: <p>I am trying to learn some Algorithms and I want to remove the duplicates using Set. I am merging two sorted arrays using my small algorithm which checks if the number from array A is small than B store in C, then later adds the remaining arrays</p>
  
  <p>I have tried but keeps getting confused</p>
  
  <pre><code>    //arrays must be sorted
      int a [] = {1,3,4,5};
      int b [] = {5,6,8,9,10};
  
      System.out.println(Arrays.toString(combineArray(a,b,3,4)));
  
  }
  
  private static int[] combineArray(int[] A, int[] B, int m, int n) {
  
      // TODO Auto-generated method stub
  
      int i = 0;
      int j = 0;
      int k = 0;
      int c [] = new int[9];
      while(i &lt;= m &amp;&amp; j &lt;= n) {
  
          if(A[i] &lt; B[j]) {
  
              c[k++] = A[i++];
  
          }else {
              c[k++] = B[j++];
          }
  
      }
  
      for(; i &lt;=m; i++) {
          c[k++] = A[i];
      }
  
      for(; j &lt;=n ; j++) {
          c[k++] = B[j];
      }
  
  
  
  
      return c;
  }
  </code></pre>
  
  <p>No error just wants some help with removing the duplicates.</p>