java8可以使用.stream().filter()方法來篩選出滿足條件的集合列表,最終返回的篩選過後的列表。 如下只獲取到集合中workflowId爲傳入的workflowId的數據集:
public WorkflowUser getAgent(Long workflowId){
List<WorkflowTransfer> transferListNotNul = list
.stream()
.filter(e -> e.getWorkflowId() != null && e.getWorkflowId().equals(workflowId))
.collect(Collectors.toList());
}