集合排序链接
集合排序链接
1.新建集合
List<String> result = Lists.newArrayList();
2.集合赋值
List<String> orderStatusList = Lists.newArrayList("60", "70", "90");
3.遍历集合
list.stream().map(CspTransferOrderInfo::getTransferOutOrderCode).filter(StringUtils::isNotBlank).collect(Collectors.toList());
4.集合逗号分割为字符串
StringUtils.join(transferOutOrderCodeList, "、")
String.join(",", cspShop.getWarehouseCodeList()
String equipmentNumberList = list.stream().map(CspWarehouseEquipment::getEquipmentNumber).collect(Collectors.joining(","));
5.Stirng 转 List
CommonUtils.stringChangeList(cspCustomerOrderInfo.getOutOrderCode())
List<String> cityCodeList = Arrays.asList(serviceProductManageBean.getDestinationCode().split(","));
6.集合分组
Map<String, List<CscCustomerInfo>> listMap = customerInfoList
.stream()
.collect(Collectors.groupingBy(CscCustomerInfo::getPostCode));
7.集合分组+转map集合
List<InterfaceMappingConfigurationDetails> mappingDetailsList = iInterfaceMappingConfigurationDetailsService.selectInterfaceMappingConfigurationDetailsList(selectInterfaceMappingDetails);
Map<String, Map<String, String>> groupByMappingType = mappingDetailsList
.stream()
.collect(Collectors.groupingBy(
InterfaceMappingConfigurationDetails::getMappingType,
Collectors.toMap(InterfaceMappingConfigurationDetails::getOmsCode,
InterfaceMappingConfigurationDetails::getErpCode,(v1,v2)->v1)
)
);
8.List转List
/**
* 集合类型转换
*
* @param longList 参数
* @return 结果
*/
private static List<String> convertToStringList(List<Long> longList) {
List<String> stringList = new ArrayList<>();
for (Long num : longList) {
stringList.add(num.toString());
}
return stringList;
}
9.List转List
String destinationCode = '12,1233,4444,32222,';
List<Long> indexIds = Arrays.stream(destinationCode.split(",")).map(Long::parseLong).collect(Collectors.toList());
10.对象转集合
Collections.singletonList(crmAllFiles.get(0))
11.返回空集合
if (CollectionUtils.isEmpty(dispatchDetailMonitorList)) {
return Collections.emptyList();
}
12.根据多个字段组合进行分组
Map<String, BmsYsbillcodeinfo> codeInfoMapsByIO = ysbillcodeinfos.stream().collect(Collectors.toMap(e -> e.getRelateCode() + e.getCodeType(), Function.identity()));
13.根据某个字段对集合进行去重
List<CspCustomerOrderDetails> rderDetails = new ArrayList<>(rderDetails.stream()
.collect(Collectors.toMap(CspCustomerOrderDetails::getGoodsCode,
order -> order, // 元素作为 value
(existing, replacement) -> existing))
.values());
// 根据外部订单号和商品编码进行去重
rderDetails = new ArrayList<>(rderDetails.stream()
.collect(Collectors.toMap(order -> order.getGoodsCode() + "-" + order.getOutOrderCode(),
Function.identity(), //
(existing, replacement) -> existing))
.values());
14.hash
HashMap<Long, BaseDataTChinaCity> chinaCityMap = baseDataTChinaCities
.stream()
.collect(HashMap::new, (a, b) -> a.put(b.getIndexId(), b), HashMap::putAll);
15.获取集合中报价方式1和报价方式2相同的对象,并给出重复提示
Map<String, List<BaseDataQuotationStructureSet>> duplicateMap = baseDataQuotationStructureSetList.stream()
.collect(Collectors.groupingBy(bdqs -> bdqs.getQuotationMethodOne() + "-" + bdqs.getQuotationMethodTwo()));
List<BaseDataQuotationStructureSet> duplicates = duplicateMap.values().stream()
.filter(list -> list.size() > 1)
.flatMap(Collection::stream)
.collect(Collectors.toList());
16.遍历分组的数据
for (Map.Entry<String, List<GetHistoryTemperatureInfoDto>> entry : temperatureInfoDtoMap.entrySet()) {
List<GetHistoryTemperatureInfoDto> list = temperatureInfoDtoMap.get(entry.getKey());
Map<String, Object> map = new HashMap<>(list.size());
list.forEach(dto -> map.put(dto.getId(), dto));
esOperationClient.bulkDataAsync("temperature_" + entry.getKey(), map);
}
17.复制实体类
BeanUtils.copyProperties(appletUserExtension, shopAppletUserExtensionVo);

文章介绍了如何在Java中使用List进行新建、赋值、遍历、字符串处理、分组以及类型转换的操作,包括流API的运用,如map、filter、collect和split等。
1336

被折叠的 条评论
为什么被折叠?



