Opening Hours :7AM to 9PM
import java.util.HashSet; class Duplicates { public void printDuplicates(int[] arr, int n) { HashSetThis program uses a HashSet to keep track of the elements that have been encountered so far. For each element in the array, the program checks if it already exists in the HashSet. If it does, it prints the element as a duplicate. If not, it adds it to the HashSet.set = new HashSet (); for (int i = 0; i < n; i++) { if (set.contains(arr[i])) { System.out.println(arr[i] + " "); } else { set.add(arr[i]); } } } } public class Main { public static void main(String[] args) { Duplicates d=new Duplicates(); int[] arr = {1, 2, 3, 4, 2, 7, 8, 8, 3}; int n = arr.length; d.printDuplicates(arr, n); } }