首页 > 其他 > 详细

两个自定义对象List列表取交集(intersection)

时间:2018-01-08 20:34:02      阅读:582      评论:0      收藏:0      [点我收藏+]
    public static void main(String[] args) {
        List<Fpxx> list = ListUtils.intersection(getFpList1(), getFpList2());
        
        for(Fpxx fp:list){
            System.out.println(fp);
        }
        
        System.out.println("size:"+list.size());
    }
    
    
    public static List<Fpxx> getFpList1() {
        List<Fpxx> list = new ArrayList<Fpxx>();
        for(int i=100000;i<200000;i++){
            Fpxx fp = new Fpxx();
            fp.fpdm = "0223678";
            fp.fphm = "3"+i;
            
            list.add(fp);
        }
        
        return list;
    }
    
    public static List<Fpxx> getFpList2() {
        List<Fpxx> list = new ArrayList<Fpxx>();
        for(int i=199900;i<199910;i++){
            Fpxx fp = new Fpxx();
            fp.fpdm = "0223678";
            fp.fphm = "3"+i;
            
            list.add(fp);
        }
        
        return list;
    }
}

class Fpxx {
    public String fpdm;
    public String fphm;

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Fpxx other = (Fpxx) obj;
        if ((this.fpdm == null) ? (other.fpdm != null) : !this.fpdm.equals(other.fpdm)) {
            return false;
        }
        if ((this.fphm == null) ? (other.fphm != null) : !this.fphm.equals(other.fphm)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Fpxx{" + "fpdm=" + fpdm + ", fphm=" + fphm + ‘}‘;
    }
    

 

两个自定义对象List列表取交集(intersection)

原文:https://www.cnblogs.com/yshyee/p/8244752.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!