12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
  2. String[] stringArr;
  3. public StringDuplicateDeleter(String[] array) {
  4. super(array);
  5. }
  6. public String[] removeDuplicates(int n){
  7. String[] newArr = new String[0];
  8. int count = 0;
  9. for(String i : array) {
  10. for(String j : array) {
  11. if(i == j) {
  12. count++;
  13. }
  14. }
  15. if(count < n) {
  16. String[] temp = new String[newArr.length + 1];
  17. for(int k = 0; k < newArr.length; k++) {
  18. temp[k] = newArr[k];
  19. }
  20. temp[temp.length - 1] = i;
  21. newArr = temp;
  22. }
  23. }
  24. String[] newArr2 = new String[]{};
  25. if(newArr.length == 1 && newArr[0] == "") {
  26. return newArr2;
  27. }
  28. else{ return newArr;
  29. }
  30. }
  31. public String[] removeDuplicatesExactly(int n) {
  32. String[] newArr = new String[0];
  33. int count = 0;
  34. for(String i : array) {
  35. for(String j : array) {
  36. if(j == i) {
  37. count++;
  38. }
  39. }
  40. if(count != n) {
  41. String[] temp = new String[newArr.length + 1];
  42. for(int k = 0; k < newArr.length; k++) {
  43. temp[k] = newArr[k];
  44. }
  45. temp[temp.length - 1] = i;
  46. newArr = temp;
  47. }
  48. }
  49. return newArr;
  50. }
  51. }