Use a Set.
private <E> boolean hasDuplicates(E[] array) {
Set<E> set = new HashSet<E>();
for(E e : array) {
if (!set.add(e)) {
return true;
}
}
return false;
}
The add() method of a set returns false if the object already exists in the set.