码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-01-08 21:14:18      阅读:2286      评论:0      收藏:0      [点我收藏+]

标签:final   ret   string   code   i++   span   util   tcl   ati   

    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)

标签:final   ret   string   code   i++   span   util   tcl   ati   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!