我想检查两个arraylist,然后插入另一个arrayList。但是当我这样做时,我会得到重复的值。如何解决此问题并删除重复项。我将获取中位数并检查中位数是否大于或小于然后将值插入第三个数组列表中。
public static void cluster() {
Kmeans kk = new Kmeans();
for (int x = 0; x < cluster1.size() && cluster1 != null; x++) {
for (int y = 0; y < cluster2.size() && cluster2 != null; y++) {
String s1 = cluster1.get(x);
String s2 = cluster2.get(y);
try {
int median = kk.distance(s1, s2);
if (s1.length() > median) {
kmcluster1.add(s1);
kmcluster2.add(s2);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
public static int median(String q, String w) {
int h = q.length();
int h1 = w.length();
int kk = 0;
if (h > h1) {
kk = h - h1;
return kk;
} else kk = h1 - h;
return kk;
}