java集合常用方法汇总

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

1.新建集合

java 复制代码
List<String> result = Lists.newArrayList();

2.集合赋值

java 复制代码
List<String> orderStatusList = Lists.newArrayList("60", "70", "90");

3.遍历集合

java 复制代码
list.stream().map(CspTransferOrderInfo::getTransferOutOrderCode).filter(StringUtils::isNotBlank).collect(Collectors.toList());

4.集合逗号分割为字符串

java 复制代码
StringUtils.join(transferOutOrderCodeList, "、")
java 复制代码
String.join(",", cspShop.getWarehouseCodeList()
java 复制代码
String equipmentNumberList = list.stream().map(CspWarehouseEquipment::getEquipmentNumber).collect(Collectors.joining(","));

5.Stirng 转 List

java 复制代码
CommonUtils.stringChangeList(cspCustomerOrderInfo.getOutOrderCode())

6.集合分组

Map<String, List> listMap = customerInfoList

.stream()

.collect(Collectors.groupingBy(CscCustomerInfo::getPostCode));

7.集合分组+转map集合

java 复制代码
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

java 复制代码
/**
     * 集合类型转换
     *
     * @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

java 复制代码
String destinationCode = '12,1233,4444,32222,';
List<Long> indexIds = Arrays.stream(destinationCode.split(",")).map(Long::parseLong).collect(Collectors.toList());
相关推荐
虾条_花吹雪5 分钟前
Chat Model API
java
双力臂40411 分钟前
MyBatis动态SQL进阶:复杂查询与性能优化实战
java·sql·性能优化·mybatis
路来了15 分钟前
Python小工具之PDF合并
开发语言·windows·python
蓝婷儿25 分钟前
Python 机器学习核心入门与实战进阶 Day 3 - 决策树 & 随机森林模型实战
人工智能·python·机器学习
六毛的毛41 分钟前
Springboot开发常见注解一览
java·spring boot·后端
AntBlack1 小时前
拖了五个月 ,不当韭菜体验版算是正式发布了
前端·后端·python
程序漫游人1 小时前
centos8.5安装jdk21详细安装教程
java·linux
.30-06Springfield1 小时前
决策树(Decision tree)算法详解(ID3、C4.5、CART)
人工智能·python·算法·决策树·机器学习
我不是哆啦A梦1 小时前
破解风电运维“百模大战”困局,机械版ChatGPT诞生?
运维·人工智能·python·算法·chatgpt
WJ.Polar1 小时前
Python数据容器-list和tuple
开发语言·python