兩個自定義對象List列表取交集(intersection)
阿新 • • 發佈:2018-01-08
ray new obj pre lean body 自定義 blog rgs
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 staticList<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)