开发中经常碰到多个list整合成一个的情况。
比较通俗易懂的做法是:
List<String> businessLicense = accessoryDto.getBusinessLicense();
List<String> agencyDocument = accessoryDto.getAgencyDocument();
List<String> otherDocuments = accessoryDto.getOtherDocuments();
List<String> productsReport = accessoryDto.getProductsReport();
List<String> threeYearsAchievements = accessoryDto.getThreeYearsAchievements();
List<String> fileIdList = new ArrayList<>();
fileIdList.addAll(businessLicense);
fileIdList.addAll(agencyDocument);
fileIdList.addAll(otherDocuments);
fileIdList.addAll(productsReport);
fileIdList.addAll(threeYearsAchievements);
使用stream实现就比较优雅了
List<String> fileIdList = ListIntegration(businessLicense,agencyDocument,otherDocuments,productsReport,threeYearsAchievements);
public List<String> ListIntegration(List<String> ...lists){
return Arrays.stream(lists).flatMap(List::stream).collect(Collectors.toList());
}