Collections,交集,并集,差集

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);


    }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值