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

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 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());