我想检查两个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