public class IntegerDuplicateDeleter extends DuplicateDeleter{ public IntegerDuplicateDeleter(Integer[] array) { super(array); } public Integer[] removeDuplicates(int maxNumberOfDuplications) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { if(getCount(array[i]) < maxNumberOfDuplications){ sb.append((array[i]) + " "); } } String arrString = sb.toString(); String [] arrPlus = arrString.split(" "); Integer[] newArr = new Integer[arrPlus.length]; for (int i = 0; i < newArr.length; i++) { try {newArr[i] = Integer.parseInt(arrPlus[i]);} catch (NumberFormatException e){} } Integer[] empty = new Integer[]{}; if (newArr.length == 1 && newArr[0] == null) { return empty; } else { return newArr;} } public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) { StringBuilder sb = new StringBuilder(); String tester = array.toString(); for (int i = 0; i < array.length; i++) { if(getCount(array[i]) < exactNumberOfDuplications || getCount(array[i]) > exactNumberOfDuplications) { sb.append((array[i]) + " "); } } String arrString = sb.toString(); String [] arrPlus = arrString.split(" "); Integer[] newArr = new Integer[arrPlus.length]; for (int i = 0; i < newArr.length; i++) { try {newArr[i] = Integer.parseInt(arrPlus[i]);} catch (NumberFormatException e){} } Integer[] empty = new Integer[]{}; if (newArr.length == 1 && newArr[0] == null) { return empty; } else { return newArr;} } private int getCount (Integer value){ int count = 0; for (Integer e : array){ if (e == value) { count++; } } return count; } }