Java 判断List集合中是否存在相同元素


判断List集合中是否存在相同元素
//校验是否存在相同资产
List<String> assetNoList = Lists.newArrayList();
beforeMergeAssetList.forEach( asset->{
    String assetNo = asset.getAssetInfo().getAssetNo();
    if (StringUtils.isBlank(assetNo)){throw new JeecgBootException("合并前资产编号不能为空");}
    assetNoList.add(assetNo);
});
Set assetNoSet=new HashSet<>(assetNoList);
if (assetNoList.size() != assetNoSet.size()) {throw new JeecgBootException("请选择不同的资产");}


0 0
讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
帮助