惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
博客园 - 司徒正美
L
LangChain Blog
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
月光博客
月光博客
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
D
DataBreaches.Net

博客园 - Bob.Xie

如何把一个本地项目上传到git MySQL导出数据字典 java 判断日期是否小于本月 生成随机字符串 工具类 vue 日期控件el-date-picker 获取选择月份的最后一天 vue 数据导入加载样式 CSS文字过多设置省略号 Spring 本地获取文件 mybatis 批量新增和修改 SpringBoot 全局统一异常拦截器 MySQL中concat,concat_ws以及group_concat的使用 Java获取当前日期属于今年的第几周 使用tesseract-ocr读取图片文字(转) element-ui表格el-table回显时默认全选数据 idea 插件库 MySQL分组修改排序序号 查看Linux服务器连接数,Oracle表和索引分析 转载:查看Oracle连接数 转载:查看ORACLE最耗时的SQL
List stream 数据处理
Bob.Xie · 2021-11-05 · via 博客园 - Bob.Xie

1、list转map

        //material_attrs name-code
        List<MaterialAttrsPO> materialAttrsPOS = materialAttrsService.queryPorscheImportMetadataAttrs();
        //字段转map
        Map<String, String> attrsMap = materialAttrsPOS.stream().collect(Collectors.toMap(MaterialAttrsPO::getName, MaterialAttrsPO::getCode));
        //attr_code list
        List<String> attrCodeList = new ArrayList<>(attrsMap.values());
        // material_attrs_options
        List<MaterialAttrsOptionsPO> attrsOptionsPOS = materialAttrsOptionsService.queryOptionsListByCodes(attrCodeList);
        // 以attrCode为key,该attrCode下所有选项值为value (groupingBy转map)
        Map<String, List<MaterialAttrsOptionsPO>> attrsOptionsAttrCodeMap = attrsOptionsPOS.stream()
                .collect(Collectors.groupingBy(MaterialAttrsOptionsPO::getAttrCode));    

2、字符串转list

Stream.of(source).collect(Collectors.toList());

3、数组转list

Arrays.stream(specificModel.split("/")).collect(Collectors.toList())

4、过滤空字符串和null值

List<String> titles = titles.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());

5、对list里面元素做处理

// 去空格 \s 可以匹配空格、制表符、换页符等空白字符的其中任意一个
List<String>  titles = titles.stream().map(str -> str.replaceAll("\\s*","")).collect(Collectors.toList());

6、根据list里面元素对象的某属性做过滤

List<String> finalTitles = titles;
List<MaterialAttrsOptionsPO>  optionsList = optionsList.stream().filter(po -> po.getAttrCode().equals(code)
                    && finalTitles.contains(po.getTitle().replaceAll("\\s*","")))
                    .collect(Collectors.toList());