今天有个需求就是一个list对象里面去除重复数据 Published on Mar 8, 2024 in Java with 0 comment 今天有个需求就是一个list对象里面去除重复数据 根据用户车牌号和用户身份证 去重 ```java package com.jinw.largescreen.entity; import cn.afterturn.easypoi.excel.annotation.Excel; import com.baomidou.mybatisplus.annotation.TableField; import com.fasterxml.jackson.annotation.JsonProperty; import com.jinw.base.model.BaseEntity; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.List; import java.util.Objects; /** * @author @liuxin * @classname MpzreListVO * @date 2024/3/7 9:14 * @description TODO */ @Data public class RoleIdListVO { @ApiModelProperty("社会服务人员id") @JsonProperty("ID") private String id; @ApiModelProperty("社会服务人员id") @JsonProperty("user_id") private String userId; /** 姓名 */ @Excel(name = "姓名") @ApiModelProperty("姓名") @JsonProperty("REAL_NAME") private String realName; /** 姓名 */ @Excel(name = "身份类型") @ApiModelProperty("服务类型") @JsonProperty("ROLE_NAME") private String roleName; /** 身份证 */ @Excel(name = "身份证") @ApiModelProperty("身份证") @JsonProperty("ID_CARD") private String idCard; /** 联系电话 */ @Excel(name = "联系电话") @ApiModelProperty("联系电话") @JsonProperty("USER_IPHONE") private String userIphone; /** 车牌号 */ @Excel(name = "车牌号") @ApiModelProperty("车牌号") @JsonProperty("PLATE_NO") private String plateNo; private Integer pageTotal; @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; RoleIdListVO that = (RoleIdListVO) o; return Objects.equals(plateNo, that.plateNo) && Objects.equals(idCard, that.idCard); } @Override public int hashCode() { return Objects.hash(plateNo, idCard); } } ``` ```java // 使用Stream API去重 returnRoleIdList = returnRoleIdList.stream() .distinct() .collect(Collectors.toList()); ``` 本文由 admin 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。