JAVA对象合集,根据条件过滤

ApplyRecord model = RecordService.getById(Apply.getId());
List<Flow> flowList = Service.queryList(model.getCode());
var flow = flowList.stream().filter(item ->model.getApplyStep().equals(item.getFlowId())).collect(Collectors.toList());
// 写lambda表达式时,getXXX获取对象 不会像C#一样自动判断非空。假如改字段为空,会报错。所以用之前,先判断非空:

if(model.getApplyStep() != null ){

  var flow = flowList.stream().filter(item ->model.getApplyStep().equals(item.getPrevFlowId())).collect(Collectors.toList());
}
原文地址:https://www.cnblogs.com/Lbox/p/13293412.html