How to find duplicate elements in an array?

Use the following code to find duplicate elements in an array.

 public static void getDuplicatesInArray(int[] ab)
    {
        boolean[] b = new boolean[99999];
        for(int i=0;i<ab.length;i++)
        {
               
                if((b[ab[i]]^true))
                {
                        b[ab[i]]=true;
                }
                else
                {
                        System.out.println(ab[i]);
                }
               
        }
    }
Interview Questions: 

Search