-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathStringDuplicateDeleter.java
More file actions
66 lines (54 loc) · 1.71 KB
/
StringDuplicateDeleter.java
File metadata and controls
66 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.zipcodewilmington.looplabs;
/**
* Created by leon on 1/28/18.
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
*/
public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
public StringDuplicateDeleter(String[] intArray) {
super(intArray);
}
@Override
public String[] removeDuplicates(int maxNumberOfDuplications) {
String without = "";
int counter = 0;
int times = 0;
for (int x = 0; x < this.array.length; x ++) {
for(int y = 0; y < this.array.length; y++) {
if (this.array[x].equals(this.array[y])) {
counter++;
}
}
if (counter < maxNumberOfDuplications) {
without += this.array[x] + " ";
times++;
}
counter = 0;
}
String[] last = without.split(" ");
if (times > 0) {
return last;
} else {
String[] going = new String[0];
return going;
}
}
@Override
public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
String without = "";
int counter = 0;
for (int x = 0; x < this.array.length; x ++) {
for(int y = 0; y < this.array.length; y++) {
if (this.array[x].equals(this.array[y])) {
counter++;
}
}
if (counter != exactNumberOfDuplications) {
without += this.array[x] + " ";
}
counter = 0;
}
String[] last = without.split(" ");
System.out.println(last);
return last;
}
}