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());
相关推荐
步步为营DotNet几秒前
深度探索.NET 中ValueTask:优化异步性能的轻量级利器
java·spring·.net
栈与堆3 分钟前
LeetCode-88-合并两个有序数组
java·开发语言·数据结构·python·算法·leetcode·rust
董世昌416 分钟前
添加、删除、替换、插入元素的全方法指南
java·开发语言·前端
超人小子7 分钟前
自动化报表系统实战:用Python让报表工作智能化
运维·python·自动化
dagouaofei8 分钟前
AI 生成 2026 年工作计划 PPT,内容质量差异在哪里
人工智能·python·powerpoint
ai_top_trends9 分钟前
2026 年工作计划汇报 PPT:AI 生成方案实测对比
人工智能·python·powerpoint
小当家.10512 分钟前
JVM八股详解(上部):核心原理与内存管理
java·jvm·学习·面试
heartbeat..12 分钟前
Spring 声明式事务:原理、使用及失效场景详解
java·spring·面试·事务
寻星探路13 分钟前
【Python 全栈测开之路】Python 基础语法精讲(三):函数、容器类型与文件处理
java·开发语言·c++·人工智能·python·ai·c#
且去填词13 分钟前
构建基于 DeepEval 的 LLM 自动化评估流水线
运维·人工智能·python·自动化·llm·deepseek·deepeval