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:
|
public class Main {
public static ArrayList<String> removeDublicates(ArrayList<String> kreuzung) {
ArrayList<String> kreuzung_copy = new ArrayList<String>();
for (int z = 0; z < kreuzung.size() - 1; z += 2) {
boolean gefunden = false;
for (int t = z - 2; t >= 0; t -= 2) { //nur erstes Vorkommen bleibt
//for (int t = z + 2; t < kreuzung.size() - 1; t += 2) { //nur letztes Vorkommen bleibt
if (kreuzung.get(t).equals(kreuzung.get(z)) && kreuzung.get(t + 1).equals(kreuzung.get(z + 1))) {
gefunden = true;
break;
}
}
if (!gefunden) {
kreuzung_copy.add(kreuzung.get(z));
kreuzung_copy.add(kreuzung.get(z + 1));
}
}
return kreuzung_copy;
}
public static void main(String[] args) {
ArrayList<String> test = new ArrayList<String>();
test.add("1");
test.add("2");
test.add("3");
test.add("4");
test.add("1");
test.add("2");
System.out.println(Arrays.toString(removeDublicates(test).toArray()));
}
} |