public class IntegerDuplicateDeleter extends DuplicateDeleter{ public IntegerDuplicateDeleter(Integer[] array){ super(array); } public Integer[] removeDuplicates(int maxNumberOfDuplications){ Integer[] newArray =new Integer[array.length]; int newArrayIndex= 0; //go through each element in the array for(Integer num : array) { int occurance = countOccurance(num); if(occurance < maxNumberOfDuplications) { newArray[newArrayIndex] = num; newArrayIndex++; } } //count occurrance Integer[] finalArray = new Integer[newArrayIndex]; System.arraycopy(newArray, 0, finalArray, 0, newArrayIndex); return finalArray; } public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications){ Integer[] newArray =new Integer[array.length]; int newArrayIndex= 0; //go through each element in the array for(Integer num : array) { int occurance = countOccurance(num); if(occurance != exactNumberOfDuplications) { newArray[newArrayIndex] = num; newArrayIndex++; } } //count occurrance Integer[] finalArray = new Integer[newArrayIndex]; System.arraycopy(newArray, 0, finalArray, 0, newArrayIndex); return finalArray; } private int countOccurance(Integer number){ int count =0; for(Integer i : array) { if(number == i) { count++; } // //when number ==} } return count; } }