title: How do you detect and delete more than two duplicates in an Array?
body: <p>How do you detect and delete if there more than two duplicates in an array. 
  In the following example, I have taken an array with the elements "10, 20, 30, 40, 40, 40, 50, 60, 70, 80 ,10". Here 40 is repeated thrice and 10 is repeated twice. I could write a program to detect two duplicates but I am not able to shrink 40(repeated thrice) to once.
  Note:- <em>I want to do this without using any java collection</em></p>
  
  <pre><code>public class ArrayDuplicate {
  public void run1()
  {
      int[] a = {10, 20, 30, 40, 40, 40, 50, 60, 70, 80 ,10};
      int size=a.length;
      System.out.println("Array size before duplicate deletion "+size);
      for(int i =0;i&lt;(size-1);i++)
      {
          for(int j=i+1;j&lt;=(size-1);j++)
          {
              if(a[i]==a[j] &amp;&amp;i!=j)
              { 
                  while(j&lt;(size-1))
                  {
                  a[j]=a[j+1];
                  j++;
  
                  }
                  size--;
              }
  
          }
      }
      System.out.print("The array after deleting the duplicates is ");
      for(int k=0;k&lt;=(size-1);k++)
      {
          System.out.print(a[k]);  //40 is being printed twice
          if(k&lt;(size-1))
          {
              System.out.print(",");
          }
          else
              System.out.print(".");
      }
  
  
  
  
  }
  public static void main(String[] args)
  {
      ArrayDuplicate ob = new ArrayDuplicate();
      ob.run1();
  
  }
  </code></pre>
  
  <p>}</p>