Removes duplicates using Hashset or TreeSet