Here you can find the source of removeDuplicates(List
Parameter | Description |
---|---|
l | list to remove duplicates from |
public static List<String> removeDuplicates(List<String> l)
//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; } }