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());
相关推荐
小小福仔1 分钟前
Python爬虫第四战(使用防盗链下载视频)
爬虫·python·音视频·反爬·防盗链referer
森叶6 分钟前
Java NIO & Java 虚拟线程(微线程)与 Go 协程的运行原理不同 为何Go 能在低配机器上承接10万 Websocket 协议连接
java·websocket·nio
明月看潮生13 分钟前
青少年编程与数学 02-016 Python数据结构与算法 23课题、分布式算法
分布式·python·算法·青少年编程·编程与数学
^_^ 纵歌14 分钟前
用python比较两个mp4是否实质相同
开发语言·python·音频·视频
一直走下去-明14 分钟前
使用python帮助艺术家完成角色动画和服装模型等任务
开发语言·图像处理·pytorch·python·opencv·ai作画
铭阳(●´∇`●)15 分钟前
Python内置函数---anext()
笔记·python·学习
程序员小蘇25 分钟前
一天一个java知识点----Tomcat与Servlet
java·servlet·tomcat
Vodka~28 分钟前
深度学习——数据处理脚本(基于detectron2框架)
人工智能·windows·深度学习
Moso_Rx42 分钟前
JavaEE——线程安全
java·安全·java-ee
恶霸不委屈44 分钟前
突破精度极限!基于DeepSeek的无人机航拍图像智能校准系统技术解析
人工智能·python·无人机·deepseek