1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import java.util.*;
  2. public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
  3. public StringDuplicateDeleter(String [] array){
  4. super(array);
  5. }
  6. public String [] removeDuplicates(int maxNumberOfDuplications){
  7. String [] newArray = new String[array.length];
  8. int newArrayIndex =0;
  9. for (String i: array){
  10. int integerCount = 0;
  11. for (String j: array){
  12. if (i.equals(j)){
  13. integerCount = integerCount +1;
  14. }
  15. }
  16. if (integerCount < maxNumberOfDuplications){
  17. newArray[newArrayIndex] = i;
  18. newArrayIndex = newArrayIndex + 1;
  19. }
  20. }
  21. String [] finalArray = Arrays.copyOf(newArray, newArrayIndex);
  22. return finalArray;
  23. }
  24. public String [] removeDuplicatesExactly(int exactNumberOfDuplications){
  25. String [] newArray = new String[array.length];
  26. int newArrayIndex = 0;
  27. for (String i : array){
  28. int integerCount = 0;
  29. for (String j : array){
  30. if (i.equals(j)){
  31. integerCount = integerCount + 1;
  32. }
  33. }
  34. if (integerCount != exactNumberOfDuplications){
  35. newArray[newArrayIndex] = i;
  36. newArrayIndex = newArrayIndex + 1;
  37. }
  38. }
  39. String[] finalArray = Arrays.copyOf(newArray, newArrayIndex);
  40. return finalArray;
  41. }
  42. }