Java tutorial
//package com.java2s; import java.util.LinkedHashSet; import java.util.Set; public class Main { public static <T> LinkedHashSet<T> getDuplicates(final Iterable<T> iterable) { LinkedHashSet<T> duplicates = new LinkedHashSet<>(); Set<T> dupeChecker = new LinkedHashSet<>(); iterable.forEach((m) -> { if (!dupeChecker.add(m)) { duplicates.add(m); } }); return duplicates; } }