public static Set<String> findDuplicates(List<String> listContainingDuplicates) {
final Set<String> setToReturn = new HashSet<String>();
final Set<String> set1 = new HashSet<String>();
for (String yourInt : listContainingDuplicates) {
if (!set1.add(yourInt)) {
setToReturn.add(yourInt);
}
}
return setToReturn;
}
//same as the Grepper awnser but for anything
//gets the amount of times the object appears in the array
public static int amountOfTimesObjectAppearsInArray(ArrayList<?> array, Object checkMe) {
int numCount = 0;
for (Object o : array) {
if (o.equals(checkMe)) numCount++;
}
return numCount;
}
//check if it appears more than once
public static boolean objectAppearsInArrayMoreThanOnce(ArrayList<?> array, Object checkMe) {
return amountOfTimesObjectAppearsInArray(array, checkMe)>1;
}