Java List Remove Duplicate removeDuplicates(List l)

Here you can find the source of removeDuplicates(List l)

Description

Remove duplicates preserving original order.

License

Open Source License

Parameter

Parameter Description
l list to remove duplicates from

Return

new list without duplicates

Declaration

public static List<String> removeDuplicates(List<String> l) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2013 Richard Hoefter and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from   ww  w .ja  v a2s. c o m*/
 * Contributors:
 *     Richard Hoefter (richard.hoefter@web.de) - initial API and implementation, bug 95300, bug 95297, bug 128104, bug 201180, bug 288830 
 *     IBM Corporation - NLS'ing and incorporating into Eclipse. 
 *                     - Bug 177833 Class created from combination of all utility classes of contribution 
 *                     - Bug 267459 Java project with an external jar file from C:\ on the build path throws a NPE during the Ant Buildfile generation.
 *                     - bug fixing
 *******************************************************************************/

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

public class Main {
    /**
     * Remove duplicates preserving original order.
     * 
     * @param l
     *            list to remove duplicates from
     * @return new list without duplicates
     */
    public static List<String> removeDuplicates(List<String> l) {
        List<String> res = new ArrayList<String>();
        for (Iterator<String> iter = l.iterator(); iter.hasNext();) {
            String element = iter.next();
            if (!res.contains(element)) {
                res.add(element);
            }
        }
        return res;
    }
}

Related

  1. removeDuplicate(List dest, List src)
  2. removeDuplicates(int[] list)
  3. removeDuplicates(List list)
  4. removeDuplicates(List listofthings)
  5. removeDuplicates(List commonVars)
  6. removeDuplicates(List collection)
  7. removeDuplicates(List list)
  8. removeDuplicates(List list, Comparator comparator)
  9. removeDuplicates(List lst)