Source Code : Removes duplicate elements from the array

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Removes duplicate elements from the array

     
import java.lang.reflect.Array;
import java.util.Enumeration;
import java.util.Hashtable;


     /*********************************************************************
     * Array manipulation for Java 1.1+.
     *
     * <p>
     * Java 1.1 compatible.
     * </p>
     *
     * @see
     *   ArrayLib2
     *
     * @version
     *   2003-04-07
     * @since
     *   2001-04-06
     * @author
     *   <a href="http://croftsoft.com/">David Wallace Croft</a>*/
public class Util{



    /*********************************************************************
    * Removes duplicate elements from the array.
    *********************************************************************/
    public static Object [ ]  removeDuplicates ( Object [ ]  array )
    //////////////////////////////////////////////////////////////////////
    {

      Hashtable  hashtable = new Hashtable ( );

      for ( int  i = 0; i < array.length; i++ )
      {
        hashtable.put ( array [ i ], array [ i ] );
      }

      Object [ ]  newArray = ( Object [ ] ) Array.newInstance (
        array.getClass ( ).getComponentType ( ), hashtable.size ( ) );

      int  index = 0;

      Enumeration  enumeration = hashtable.elements ( );

      while ( enumeration.hasMoreElements ( ) )
      {
        newArray [ index++ ] = enumeration.nextElement ( );
      }

      return newArray;
    }


}

   
    
    
    
    
  

Thank with us