2 つの arraylist をチェックしてから、別の arrayList に挿入したい。しかし、そうすると、重複した値が得られます。この問題を解決して重複を削除する方法。中央値を取得し、中央値がそれより大きいか小さいかを確認し、3 番目の 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;
}