Here you can find the source of selectDuplicateQualifiers( List
public static <T> Collection<T> selectDuplicateQualifiers( List<T> elements)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2013 Borland Software Corporation and others. * /*from w w w . j av a2s. c om*/ * 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 * * Contributors: * Borland Software Corporation - initial API and implementation * Christopher Gerking - bug 289982 * Alex Paperno - bugs 424584 *******************************************************************************/ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main { public static <T> Collection<T> selectDuplicateQualifiers( List<T> elements) { Set<T> result = null; for (T nextQualifier : elements) { if (Collections.frequency(elements, nextQualifier) > 1) { if (result == null) { result = new HashSet<T>(2); } result.add(nextQualifier); } } return (result != null) ? result : Collections.<T> emptySet(); } }