判断 list 集合是否含有重复对象
作者:互联网
/**
* true 重复
* @param orderList
* @return
*/
private boolean containsRepeatAttachment(List<DesignSoftwareUnifiedEngineeringAttachmentDTO> orderList) {
if(org.springframework.util.CollectionUtils.isEmpty(orderList)){
return false;
}
if(orderList.size() == 1){
return false;
}
Set<String> keys = new HashSet<>(orderList.size());
for (int i = 0; i < orderList.size(); i++) {
final String key = new StringBuffer(orderList.get(i).getName()).append(orderList.get(i).getSuffix()).toString();
if(keys.contains(key)){
return true;
}else{
keys.add(key);
}
}
return false;
}
标签:false,重复,orderList,list,keys,key,集合,return,size 来源: https://blog.csdn.net/dgutliangxuan/article/details/116157520