package org.cdp.cloud2.model.bo; import java.util.HashSet; import java.util.Set; /** * Created by Joel.Yang on 2016/9/13. */ public class CPyC013 { private Integer py013Id; private Integer calPeriod; private Integer calYear; private Integer calMonth; private Long startDate; private Long endDate; private Integer lastCalYear; private Integer lastCalMonth; public Integer getPy013Id() { return py013Id; } public void setPy013Id(Integer py013Id) { this.py013Id = py013Id; } public Integer getCalPeriod() { return calPeriod; } public void setCalPeriod(Integer calPeriod) { this.calPeriod = calPeriod; } public Integer getCalYear() { return calYear; } public void setCalYear(Integer calYear) { this.calYear = calYear; } public Integer getCalMonth() { return calMonth; } public void setCalMonth(Integer calMonth) { this.calMonth = calMonth; } public Long getStartDate() { return startDate; } public void setStartDate(Long startDate) { this.startDate = startDate; } public Long getEndDate() { return endDate; } public void setEndDate(Long endDate) { this.endDate = endDate; } public Integer getLastCalYear() { return lastCalYear; } public void setLastCalYear(Integer lastCalYear) { this.lastCalYear = lastCalYear; } public Integer getLastCalMonth() { return lastCalMonth; } public void setLastCalMonth(Integer lastCalMonth) { this.lastCalMonth = lastCalMonth; } @Override public boolean equals(Object obj) { CPyC013 s=(CPyC013)obj; return s.getCalMonth().equals(((CPyC013) obj).getCalMonth()) ; } @Override public int hashCode() { String in = this.calMonth+""; return in.hashCode(); } // 去重 public static void main(String[] args) { CPyC013 c=new CPyC013(); CPyC013 c1=new CPyC013();c1.setCalMonth(1); CPyC013 c2=new CPyC013();c2.setCalMonth(2); Set<CPyC013> result = new HashSet<CPyC013>(); Set<CPyC013> set1 = new HashSet<CPyC013>() ; set1.add(c); set1.add(c1); set1.add(c2); Set<CPyC013> set2 = new HashSet<CPyC013>() ; set2.add(c); set2.add(c1); set2. add(c2); result.clear(); result.addAll(set1); result.retainAll(set2); System.out.println("交集:"+result); result.clear(); result.addAll(set1); result.removeAll(set2); System.out.println("差集:"+result); result.clear(); result.addAll(set1); result.addAll(set2); System.out.println("并集:"+result); } }
Collections,交集,并集,差集
最新推荐文章于 2024-05-20 17:41:15 发布