java集合常用方法汇总

集合排序链接
集合排序链接

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())

6.集合分组

Map 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());

你可能感兴趣的:(web,JAVA,编程,java,python,windows)