【发布时间】:2017-08-29 20:11:24
【问题描述】:
我的对象有一些领域。
public class MyObject{
private String a;
private String b;
}
我有一个 Set 包含这样的对象:
Set<MyObject> thirdSet = new HashSet<MyObject>();
Set<MyObject> firstSet=getFirstSet();
Set<MyObject> secondSet = getSecondeSet();
for (MyObjectobj : firstSet) {
if (!secondSet.contains(obj)) {
thirdSet.add(obj);
}
}
我需要将我的 secondSet 中不包含的所有 obj 选择到 thridSet 中(obj 的值不是通过引用) 有可能还是使用收集更好?
【问题讨论】: