A、B两个List 比较

mac2025-05-02  5

第一步:重写Object的hashCode()方法跟equals()方法: //重写hashCode和equals @Override public int hashCode() { String result = wellId+wellboreStatus+areaIdentify+wellName+wellboreId; return result.hashCode(); } @Override public boolean equals(Object obj) { RtocDeptwelllControlResult u = (RtocDeptwelllControlResult)obj; return this.getWellId().equals(u.getWellId()) && (this.getWellboreStatus().equals(u.getWellboreStatus())) && (this.getAreaIdentify().equals(u.getAreaIdentify())) && (this.getWellName().equals(u.getWellName())) && (this.getWellboreId().equals(u.getWellboreId())); }

第二步:实例: HashSet h1 = new HashSet(ListBean); HashSet h2 = new HashSet(DeptwelllControl); h1.removeAll(h2); listAdd.addAll(h1); HashSet h3 = new HashSet(ListBean); HashSet h4 = new HashSet(DeptwelllControl); h4.removeAll(h3); listDelete.addAll(h4); listAdd集合里面的内容就是ListBean中有,DeptwelllControl中没有的。 listDelete集合里面的内容是DeptwelllControl集合中有,ListBean中没有的

最新回复(0)