Stream api2

Collect to Map

1
2
3
Map<String, String> result = effectList.stream().collect(
            Collectors.toMap(BusiDisposalProveEffectInfo::getDeclareId,
                            BusiDisposalProveEffectInfo::getRegAttachmentId));

Collect to List or Set

1
List<String> idList = resultList.stream().map(BusiDisposalProveListVO::getId).collect(Collectors.toList());

Filter

1
2
3
4
Set<String> idSet = resultList.stream()
                .filter(e -> StringUtils.equals(e.getStatus(), DeclareStatusEnum.SUCCESS.getCode()))
                .map(BusiDisposalProveListVO::getId)
                .collect(Collectors.toSet());

Consumer

1
2
3
4
5
6
7
8
// 相加并将结果回调回去
public void f1(int a,int b,Consumer<Integer> callback){
  callback.accept(a+b);
}
// 调用并打印
f1(1,2,result -> {
  System.out.println(result);
})