判断一个元素在list集合内出现的次数

  List<DeviceSpotCheck> deviceSpotCheckList = listMap.get(deviceCode);
  List<String> collect = deviceSpotCheckList.stream().map(DeviceSpotCheck::getCheckCode).collect(Collectors.toList());
  if (Collections.frequency(collect,checkCode) >= 1){
        failMsg.append("点检编码已存在该设备下,不允许重复,");
  }

主要就是下面这行代码

Collections.frequency(collect,checkCode)

 

posted @ 2024-07-01 13:57  多多指教~  阅读(2)  评论(0编辑  收藏  举报