-
Notifications
You must be signed in to change notification settings - Fork 0
/
Uniqelem.java
49 lines (41 loc) · 1.36 KB
/
Uniqelem.java
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
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Uniqelem {
public static boolean found(String item, String[] list) {
for (int i = 0; i < list.length; ++i) {
if (list[i] != null && list[i].equals(item)) {
return true;
}
}
return false;
}
public List<String> getUniqueElements(String line) {
String[] lineArray = line.split(",");
String[] uniqueArray = new String[lineArray.length];
int count = 0;
for (int i = 0; i < lineArray.length; ++i) {
if (!found(lineArray[i], uniqueArray)) {
uniqueArray[count] = lineArray[i];
++count;
}
}
List<String> result = new ArrayList<>();
for (String s : uniqueArray) {
if (s != null) {
result.add(s);
}
}
return result;
}
public static void main(String[] args) throws IOException {
File file = new File(args[0]);
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
Uniqelem uniqelem = new Uniqelem();
while ((line = in.readLine()) != null) {
List<String> uniqueElements = uniqelem.getUniqueElements(line);
System.out.println(String.join(",", uniqueElements));
}
}
}