我可以使用Java Stream API ???
重写以下代码 List<ActionAttributeType> actionAttributeTypes = executeActionRsType.getBody().getActionAttributes();
for (ActionAttributeType actionAttributeType : actionAttributeTypes) {
if (actionAttributeType.getAttributeCode().equals("CONTRACTID")) {
remoteBankingContractId = actionAttributeType.getAttributeValue();
break;
}
}
答案 0 :(得分:1)
这可以帮到你:
remoteBankingContractId = executeActionRsType.getBody().getActionAttributes().stream().filter(e -> "CONTRACTID".equals(e.getAttributeCode())).findFirst().orElse(null);
或者为您的变量类型获取Optional
:
Optional<TypeOfYourVariable> remoteBankingContractId = executeActionRsType.getBody().getActionAttributes().stream().filter(e -> "CONTRACTID".equals(e.getAttributeCode())).findFirst();