Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to retain/get only the duplicate elements in a list ~ foundjava

Tags: duplicate
Let’s say you have a list of Duplicate (and non-duplicate) items, and you want a new collection with only the duplicate items in there. The easiest way is to extend the HashSet.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class DuplicatesOnlySetextends HashSet
{
    private final Set uniques = new HashSet();
 
    public  DuplicatesOnlySet(Collection extends E> c)
    {
        super.addAll(c);
    }
 
    @Override
    public


This post first appeared on Found Java, please read the originial post: here

Share the post

How to retain/get only the duplicate elements in a list ~ foundjava

×

Subscribe to Found Java

Get updates delivered right to your inbox!

Thank you for your subscription

×