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 天前
Maven中optional的作用
java·jenkins·maven
Dan.Qiao1 天前
pycharm如何处理python项目间引用
ide·python·pycharm
云和数据.ChenGuang1 天前
java常见SSL bug解决方案
java·bug·ssl
songx_991 天前
leetcode29( 有效的括号)
java·数据结构·算法·leetcode
于樱花森上飞舞1 天前
【java】常见排序算法详解
java·算法·排序算法
维持好习惯1 天前
复杂Excel文件导入功能(使用AI快速实现)
java·spring boot·excel
万粉变现经纪人1 天前
如何解决pip安装报错ModuleNotFoundError: No module named ‘sympy’问题
python·beautifulsoup·pandas·scikit-learn·pyqt·pip·scipy
dyxal1 天前
使用tree命令导出文件夹/文件的目录树( Windows 和 macOS)
windows·macos·策略模式
酷炫码神1 天前
第 2 篇:Java 入门实战(JDK8 版)—— 编写第一个 Java 程序,理解基础运行逻辑
java·开发语言·策略模式
月阳羊1 天前
【硬件-笔试面试题-93】硬件/电子工程师,笔试面试题(知识点:波特图)
java·经验分享·单片机·嵌入式硬件·面试