import java.util.*; public class FindDuplicateStudents{ public static void main(String args[]) { Collection students = new ArrayList<>(); students.add(new Student("John", "Smith")); students.add(new Student("Stanley", "Peters")); students.add(new Student("Edgar", "Bloch")); students.add(new Student("Suzan", "Miles")); students.add(new Student("Mary", "Poppins")); students.add(new Student("John", "Smith")); students.add(new Student("Stanley", "Peters")); Collection uniques = new HashSet(); Collection dups = new HashSet(); for(Student st : students) { if(uniques.contains(st)) dups.add(st); else uniques.add(st); } uniques.removeAll(dups); System.out.println("-- Uniques --"); print(uniques); System.out.println("-- Dups --"); print(dups); } public static void print(Collection collection) { Iterator it = collection.iterator(); while(it.hasNext()) System.out.println(it.next()); } }