java 集合stream流的妙用

  1. 做属性值过滤
// eg : List 集合找出 clothTrackType 为 1 的所有记录
List<ClothEntity> bus =  buShaLists.stream()
                       .filter(i->i.getClothTrackType().equals(1))
                       .collect(Collectors.toList());
  1. 判断集合中某个记录符合条件,就返回true值。
// 老代码
for (ClothEntity item : bus){
    if (item.getSliceAmount()>2){
        // 纱的片数大于2 就有左右拼接
        shaWorkProcessList.add("左右拼接");
        break;
    }
}
// 优化后
// eg: List 集合 中只要有一条记录的单双层的值为2 则为 true
bus.stream().anyMatch(i -> i.getDoubleDeck().equals(2))

持续更新…

你可能感兴趣的:(java,开发语言)