流的使用之“如何将List<String>转为Map”
流的使用之“如何将List<String>转为Map”
ProductIllegalCustom query = new ProductIllegalCustom();
query.setUnionSkus(unionSkus);
Map<String, String> illegalMap = productIllegalService.getProductIllegalList(query).stream().filter(item -> StringUtils.isNotEmpty(item.getIllegalReason())).map(item -> {
List<String> skus = Optional.ofNullable(CommonUtils.tokenizeToStringList(item.getSimilarSkuList())).orElse(Lists.newArrayList());
skus.add(item.getProductSku());
// List<String> SKU.流化.去重.过滤空值.map(sku -> KeyValue存储<key, value>).转为List【当前应为List<KeyValue<String,String>>】
return skus.stream().distinct().filter(StringUtils::isNotEmpty).map(sku -> new KeyValue<>(sku, item.getIllegalReason())).collect(Collectors.toList());
// 降级流化KeyValue<String,String>.转为Map<String, String>
}).flatMap(Collection::stream).collect(Collectors.toMap(KeyValue::getKey, KeyValue::getValue, (key1, key2) -> key1));
KeyValue对象
public class KeyValue<K, V>
{
private K key; private V value; public KeyValue()
{
} public KeyValue(K key, V value)
{
this.key = key;
this.value = value;
} public K getKey()
{
return key;
} public void setKey(K key)
{
this.key = key;
} public V getValue()
{
return value;
} public void setValue(V value)
{
this.value = value;
}
}
流的使用之“如何将List<String>转为Map”的更多相关文章
- net.sf.json将string转为map
背景 改一个以前的项目,项目里只有这个包,虽然我想用gson或者fastjson,然而并不想引入新的jar.于是使用这个,特此记录,感觉贼不好用. 实现代码 entity.getData()的值:{a ...
- getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:
直接遍历报错:[Ljava.lang.String;@44739f3f Map<String, String> tempMap = new HashMap<String, Strin ...
- [C#]List<int>转string[],string[]转为string
// List<int>转string[] public string[] ListInt2StringArray(List<int> input) { return Arra ...
- JSON 与 String、Map、JavaBean互转
JSON 与 String.Map.JavaBean互转 //解析远程登录用户信息 AttributePrincipal principal = AssertionHolder.getAssertio ...
- HDU 4287 Intelligent IME(string,map,stl,make_pair)
题目 转载来的,有些stl和string的函数蛮好的: //numx[i]=string(sx); //把char[]类型转换成string类型 // mat.insert(make_pair(num ...
- JAVA中List转换String,String转换List,Map转换String,String转换Map之间的转换类
<pre name="code" class="java"></pre><pre name="code" cl ...
- Iterator<Entry<String,String>> iter=map.entrySet().iterator(); 是什么意思
//获得map的迭代器,用作遍历map中的每一个键值对Iterator是迭代器,map之前应该定义过,姑且认为是HashMap.<Entry<String,String>>表示 ...
- {}typeof string转为 obj json
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.3/jquer ...
- Jackson将json string转为Object,org.json读取json数组
从json文件读取json string或者自定义json string,将其转为object.下面采用的object为map,根据map读取json的某个数据,可以读取第一级的数据name,后来发现 ...
- POST 发送HTTP请求入参为:String url, Map<String, Object> propsMap
/** * 发送HTTP请求 * * @param url * @param propsMap * 发送的参数 */ public static String httpSend(String url, ...
随机推荐
- 关于 False、True、0、1、tinyint(1) 的说明
MySQL 保存 Boolean 值时,用 1 代表 TRUE,0 代表 FALSE:类似一个 bit 位,默认没有数据,即为 0,也即 Faslse MySQL 存储 Boolean 值的类型为 t ...
- Python类型提示完全指南:用类型安全重构你的代码,提升10倍开发效率
title: Python类型提示完全指南:用类型安全重构你的代码,提升10倍开发效率 date: 2025/2/23 updated: 2025/2/23 author: cmdragon exce ...
- 洛谷P11380 [GESP202412 八级] 排队 题解
数据太可恶了,竟然有重边!!! 题目传送门. 显然一道简单图论题. 把 \(a_i\) 和 \(b_i\) 的关系想象成一条有向边,于是可以得出:如果 \(x\) 的出度大于 \(1\) 或者 \(x ...
- Cython与CUDA之Add
技术背景 在前一篇文章中,我们介绍过使用Cython结合CUDA实现了一个Gather算子以及一个BatchGather算子.这里我们继续使用这一套方案,实现一个简单的求和函数,通过CUDA来计算数组 ...
- 第十八届全国大学生信息安全竞赛暨第二届“长城杯”铁人三项赛web方向部分wp
第十八届全国大学生信息安全竞赛暨第二届"长城杯"铁人三项赛web方向部分wp hello_web 查看源代码发现有两个文件,访问一下 Tips是phpinfo 里面可以看到disa ...
- Ubuntu Nvidia driver驱动安装(新)
前言 英伟达更新了安装驱动的方式,更新一下文档 旧文:Ubuntu Nvidia driver驱动安装及卸载 下载官方驱动安装 1.安装驱动前一定要更新软件列表和安装必要软件.依赖(必须) sudo ...
- 请求方法:GET 与 POST
根据 RFC 规范,GET 的语义是从服务器获取指定的资源,GET 请求的参数位置一般是写在 URL 中,URL 规定只能支持 ASCII,所以 GET 请求的参数只允许 ASCII 字符 ,而且浏览 ...
- Panabit 流控软件的使用教程
Flow control software-Panabit Howto Version 1.0.0 Date 2010-11-21 Author ipcpu Website http://www.ip ...
- study Rust-5【Slice】
另一个没有所有权的数据类型是 slice.slice 允许你引用集合中一段连续的元素序列,而不用引用整个集合. [字符串Slice熟悉掌握的很勉强,通过动手来进步加深认识] 字符串slice let ...
- BotSharp + MCP 三步实现智能体开发
1. 简介 1.1 什么是MCP Model Context Protocol(MCP)模型上下文协议是一种标准化协议,它让大模型能够更容易地和外部的数据.工具连接起来.你可以把MCP想象成一个通用的 ...