zoukankan      html  css  js  c++  java
  • 两个自定义对象List列表取交集(intersection)

        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 + '}';
        }
        
  • 相关阅读:
    51NOD 1371填数字
    51NOD1052 最大M字段和
    ZROI2018提高day4t3
    ZROI2018提高day4t2
    ZROI2018提高day4t1
    ZROI2018普转提day2t4
    ZROI2018普转提day2t2
    ZROI2018普转提day2t1
    ZROI2018普转提day2t3
    ZROI2018提高day3t3
  • 原文地址:https://www.cnblogs.com/yshyee/p/8244752.html
Copyright © 2011-2022 走看看