我想檢查兩個arraylist,然後插入到另一個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;
}
請格式化您的代碼。 – 2013-04-29 16:27:04
你能在我的代碼中發現錯誤嗎? – newuser 2013-04-29 16:33:27