流的使用之“如何将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, ...
随机推荐
- 计算机基础知识问答:C/C++篇
讲解一下C语言内存空间的模型: 代码区:它是用来存放程序执行代码的一块内存区域.通常,这部分区域是只读的,防止程序意外地修改了它的指令. 常量区:数据段包含了程序中已初始化的全局变量和静态变量.而BS ...
- C#反射机制学习
参考原文链接:https://blog.csdn.net/xiaouncle/java/article/details/52983924 反射是.NET中的重要机制,通过反射可以得到*.exe或*.d ...
- 执行shell脚本报错:Syntax error: word unexpected (expecting "in")
检查语法无误后,考虑是脚本文件换行符的问题. vs创建的文件默认以CRLF(0D0A)换行. 然而对于换行,windows用CRLF(0D0A)表示,linux用LF(0A)表示. 切换脚本文件换行符 ...
- 解决 Dell PowerEdge T630 增加第三方 PCIe 设备后制冷系统异常
博客链接:解决 Dell PowerEdge T630 增加第三方 PCIe 设备后制冷系统异常 配置 Device: Dell PowerEdge T630 CPU: Intel(R) Xeon(R ...
- rabbitmq的基本使用
使用MQ的三大作用:1.同步变异步2.流量削峰3.解耦降低服务间的耦合性要不要使用MQ,需不需要使用MQ依据项目的需要做选择. 使用场景: 例如:注册用户时候,发送激活邮件.监控应用中抛出的异常,邮件 ...
- 详解vue-router基本使用
来源:https://m.jb51.net/article/111499.htm 本篇文章主要介绍了详解vue-router基本使用,详细的介绍了vue-router的概念和用法,有兴趣的可以了解 ...
- AI与.NET系列文章之三:在.NET中使用大语言模型(LLMs)
引言 在技术迅猛发展的今天,大语言模型(Large Language Models, LLMs)已成为人工智能领域的核心驱动力之一.从智能对话系统到自动化内容生成,LLMs的应用正在深刻改变我们的工作 ...
- springboot报错说 Failed to parse multipart servlet request; nested exception is java.io.IOException
问题:一次开发中遇到一个springboot的异常,如下所示:Failed to parse multipart servlet request; nested exception is java.i ...
- ESXi、PVE、unRaid对比
目录 收起 [前言] [概述] [系统安装] [系统资源占用] [创建/编辑虚拟机] [硬盘直通] [PCI硬件直通] [显卡直通] [虚拟光驱] [自动开机.关机] [网络管理] [稳定性] [CP ...
- PLSQL中查询数据的时候查询结果显示中文乱码
要需要很努力才能看起来毫不费力.....1.在PLSQL中查询数据的时候查询结果显示中文乱码这里写图片描述2.需要在环境变量中新建两个环境变量:第一个:设置 NLS_LANG=SIMPLIFIED C ...