Java List Remove Duplicate removeDuplicates(int[] list)

Here you can find the source of removeDuplicates(int[] list)

Description

Removes dupicated entries from the list.

License

Open Source License

Parameter

Parameter Description
list the list

Return

the list without any duplicated entries

Declaration

public static int[] removeDuplicates(int[] list) 

Method Source Code

//package com.java2s;
/***************************************************************
 *  This file is part of the [fleXive](R) framework.
 *
 *  Copyright (c) 1999-2014/*from  ww  w.  j  av  a2 s. c  o m*/
 *  UCS - unique computing solutions gmbh (http://www.ucs.at)
 *  All rights reserved
 *
 *  The [fleXive](R) project is free software; you can redistribute
 *  it and/or modify it under the terms of the GNU Lesser General Public
 *  License version 2.1 or higher as published by the Free Software Foundation.
 *
 *  The GNU Lesser General Public License can be found at
 *  http://www.gnu.org/licenses/lgpl.html.
 *  A copy is found in the textfile LGPL.txt and important notices to the
 *  license from the author are found in LICENSE.txt distributed with
 *  these libraries.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  For further information about UCS - unique computing solutions gmbh,
 *  please see the company website: http://www.ucs.at
 *
 *  For further information about [fleXive](R), please see the
 *  project website: http://www.flexive.org
 *
 *
 *  This copyright notice MUST APPEAR in all copies of the file!
 ***************************************************************/

import java.util.Collections;
import java.util.Enumeration;
import java.util.Hashtable;

public class Main {
    /**
     * Removes dupicated entries from the list.
     *
     * @param list the list
     * @return the list without any duplicated entries
     */
    public static int[] removeDuplicates(int[] list) {
        if (list == null || list.length == 0) {
            return new int[0];
        }
        Hashtable<Integer, Boolean> tbl = new Hashtable<Integer, Boolean>(
                list.length);
        for (int ele : list) {
            tbl.put(ele, Boolean.FALSE);
        }
        int[] result = new int[tbl.size()];
        int pos = 0;
        for (Enumeration e = tbl.keys(); e.hasMoreElements();) {
            result[pos++] = (Integer) e.nextElement();
        }
        return result;
    }

    /**
     * Removes dupicated entries from the list.
     *
     * @param list the list
     * @return the list without any duplicated entries
     */
    public static long[] removeDuplicates(long[] list) {
        if (list == null || list.length == 0) {
            return new long[0];
        }
        Hashtable<Long, Boolean> tbl = new Hashtable<Long, Boolean>(
                list.length);
        for (long ele : list) {
            tbl.put(ele, Boolean.FALSE);
        }
        long[] result = new long[tbl.size()];
        int pos = 0;
        for (long element : Collections.list(tbl.keys())) {
            result[pos++] = element;
        }
        return result;
    }
}

Related

  1. removeDublicates(List l)
  2. removeDup(List lst)
  3. removeDuplicate(Collection entityList)
  4. removeDuplicate(List uidList)
  5. removeDuplicate(List dest, List src)
  6. removeDuplicates(List list)
  7. removeDuplicates(List listofthings)
  8. removeDuplicates(List commonVars)
  9. removeDuplicates(List l)