2 个不同的对象集合如何取交集和差集
//@com.fasterxml.jackson.annotation.JsonIgnore
private Date create_time;
/**
修改时间
*/
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
// @com.fasterxml.jackson.annotation.JsonIgnore
private Date update_time;
/**
是否删除 0、未删除 1、已删除
*/
private Integer is_delete;
public TbHuidou() {
}
/**
重写 eques 方法
@param o
@return
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TbHuidou tbHuidou = (TbHuidou) o;
return dzh_no.equals(tbHuidou.dzh_no) && lc_no.equals(tbHuidou.lc_no) && product_code.equals(tbHuidou.product_code) && function_id.equals(tbHuidou.function_id);
}
/**
重写 hascode 方法
@return
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 17;
result = prime * result + (dzh_no == null ? 0 : dzh_no.hashCode());
result = prime * result + (lc_no == null ? 0 : lc_no.hashCode());
result = prime * result + (product_code == null ? 0 : product_code.hashCode());
result = prime * result + (function_id == null ? 0 : function_id.hashCode());
return result;
}
TrequestHuiDouVo
/**
理财号
*/
private String vc_custno;
/**
组合代码
*/
private String vc_combcode;
/**
基金代码
*/
private String vc_fundcode;
取交集代码?tbHuidous 数据不能重复 否则需要先去重复
public static void main(String[] args) {
List<TbHuidou> tbHuidous = new ArrayList<>();
TbHuidou tbHuidou = new TbHuidou();
tbHuidou.setCf_no("1");
tbHuidou.setDzh_no("1");
tbHuidou.setLc_no("1");
tbHuidou.setProduct_code("1");
tbHuidou.setFunction_id("1");
tbHuidou.setProduct_type("1");
tbHuidous.add(tbHuidou);
TbHuido 《一线大厂 Java 面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 u tbHuidou2 = new TbHuidou();
tbHuidou2.setCf_no("2");
tbHuidou2.setDzh_no("2");
tbHuidou2.setLc_no("2");
tbHuidou2.setProduct_code("2");
tbHuidou2.setFunction_id("2");
tbHuidou2.setProduct_type("2");
tbHuidous.add(tbHuidou2);
List<TrequestHuiDouVo> list = new ArrayList<>();
TrequestHuiDouVo trequestHuiDouVo = new TrequestHuiDouVo();
trequestHuiDouVo.setVc_custno("1");
trequestHuiDouVo.setVc_fundcode("1");
list.add(trequestHuiDouVo);
TrequestHuiDouVo trequestHuiDouVo2 = new TrequestHuiDouVo();
trequestHuiDouVo2.setVc_custno("2");
trequestHuiDouVo2.setVc_combcode("2");
list.add(trequestHuiDouVo2);
TrequestHuiDouVo trequestHuiDouVo3 = new TrequestHuiDouVo();
trequestHuiDouVo3.setVc_custno("7");
trequestHuiDouVo3.setVc_combcode("7");
list.add(trequestHuiDouVo3);
List<TbHuidou> list3 = tbHuidous.stream().filter(one -> {
List<Boolean> result = list.stream().map(two -> {
if (one.getProduct_type().equals("1") && one.getLc_no().equals(two.getVc_custno()) && one.getProduct_code().equals(two.getVc_fundcode())){
return true;
}else if (one.getProduct_type().equals("2") && one.getLc_no().equals(two.getVc_custno()) && one.getProduct_code().equals(two.getVc_combcode())){
return true;
}else {
return false;
}
// return one == two;
}).collect(Collectors.toList());
if (result.indexOf(true) > -1)
return true;
return false;
}).collect(Collectors.toList());
list3.stream().forEach(System.out::println);
}
取差集代码
public static void main(String[] args) {
List<TbHuidou> tbHuidous = new ArrayList<>();
TbHuidou tbHuidou = new TbHuidou();
tbHuidou.setCf_no("1");
tbHuidou.setDzh_no("1");
tbHuidou.setLc_no("1");
tbHuidou.setProduct_code("1");
tbHuidou.setFunction_id("1");
tbHuidou.setProduct_type("1");
tbHuidous.add(tbHuidou);
TbHuidou tbHuidou2 = new TbHuidou();
tbHuidou2.setCf_no("2");
tbHuidou2.setDzh_no("2");
tbHuidou2.setLc_no("2");
tbHuidou2.setProduct_code("2");
tbHuidou2.setFunction_id("2");
tbHuidou2.setProduct_type("2");
tbHuidous.add(tbHuidou2);
TbHuidou tbHuidou3 = new TbHuidou();
评论