我应该如何只获得一次非匹配元素? 我的代码如下:
Set<String> hashSet = new HashSet<String>(); //consist 90 elements
Set<Object> hashSet2 = new HashSet<Object>();// consist 9 elements
for (String string : hashSet ) {
for(Object obj: hashSet2){
if(obj.equals(string)){
System.out.println(string + "\t is present in tracking sheet");
}
if(!obj.equals(string)){
System.out.println(string + "\t is not sheet");
}
}
}
首先使用if()我能够获得两个集合中的元素。 使用第二个if()我得到第一组中所有元素的结果。
输出: GBS-40747不在表单中
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is present in tracking sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-40747 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is present in tracking sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-35562 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is present in tracking sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
GBS-39321 is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
0.8 build is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is present in tracking sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-39421 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-38455 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is present in tracking sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-40695 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-38467 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
GBS-41315 is not in sheet
感谢大家提供他们的意见和解决方案。我选择了一个作为接受的答案(KISS:保持简短和简单)(如果允许,会选择更多:-)),但很多都有帮助。
答案 0 :(得分:3)
请坚持下去:
Set<String> hashSet = new HashSet<String>(); // consist 90 elements
Set<Object> hashSet2 = new HashSet<Object>(); // consist 9 elements
for (String string : hashSet) {
if (hashSet2.contains(string)) {
System.out.println(string + "\t is present in tracking sheet");
} else {
System.out.println(string + "\t is not sheet");
}
}
答案 1 :(得分:1)
尝试使用布尔值,如果找到则可以设置为true。我认为您找到break
String
for (String string : hashSet ) {
boolean found = false;
for(Object obj: hashSet2){
if(obj.equals(string)){
found = true;
break;
}
}
if (found) {
System.out.println(string + "\t is present in tracking sheet");
} else {
System.out.println(string + "\t is not sheet");
}
}
答案 2 :(得分:1)
您可以使用CollectionUtils库进行析取()。这将返回一个包含两个集合之间不共享的元素的集合。
Collection nonMatchingSet = CollectionUtils.disjunction(hashSet , hashSet2);
答案 3 :(得分:1)
您可以轻松起诉Set
。
Set<String> hashSet = new HashSet<>();
Set<Object> hashSet2 = new HashSet<>();
hashSet.add("1");
hashSet.add("2");
hashSet.add("4") ;
hashSet2.add("1");
hashSet2.add("3");
hashSet2.add("5");
Set<Object> temp=new HashSet<>();
temp.addAll(hashSet2);
hashSet2.removeAll(hashSet); // remove common elements
hashSet.removeAll(temp);// remove common elements
hashSet2.addAll(hashSet); // add unique values sets
System.out.println(hashSet2);
Out put:
[3, 2, 5, 4]
答案 4 :(得分:1)
代码
List<String> list1 = Arrays.asList("1", "2", "3");
List<String> list2 = Arrays.asList("1", "2", "4", "5");
Set<String> hashSet = new HashSet<>(list1);
Set<String> hashSet2 = new HashSet<>(list2);
hashSet.retainAll(hashSet2);
Set<String> totallSet = Stream.of(list1,list2)
.flatMap( string -> string.stream())
.collect(Collectors.toSet());
totallSet.removeAll(hashSet);
totallSet.forEach(i -> System.out.print(" " + i));
输出:
3,4,5
答案 5 :(得分:0)
尝试此解决方案,在此代码中,hashset2中等于hashset2中的对象的hashset中的所有项目都从hashset中删除:
hashSet.removeAll(hashSet2);
for (String s : hashSet) {
System.out.println(s + " is not in sheet !");
}
答案 6 :(得分:0)
obj
是Object
类的实例。并且您在此处obj.equals(string)
表示您正在调用Object's equals method
,这等于方法检查identity check
。但是为了找到相似性,您需要检查equality check
。
答案 7 :(得分:0)
hashSet.retainAll
方法还可以帮助您从hashSet2中删除所有不在hasSet中的项目,以便运行以下语句后:
hashSet.retainAll(hashSet2);
hashSet2只包含hashSet中存在的元素。它们存在于跟踪表中。
答案 8 :(得分:0)
package Example;
import java.util.*;
public class CopyOfSample2 {
public static void main(String s[]){
Set<String> set1=new HashSet<String>();
Set<String> set2=new HashSet<String>();
Set<String> difference=new HashSet<String>(set1);
set1.add("1");
set1.add("5");
set1.add("2");
set2.add("3");
set2.add("2");
set2.add("1");
difference.removeAll(set2);
System.out.println("Difference" +difference);
}
}