流的使用之“如何将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”的更多相关文章

  1. net.sf.json将string转为map

    背景 改一个以前的项目,项目里只有这个包,虽然我想用gson或者fastjson,然而并不想引入新的jar.于是使用这个,特此记录,感觉贼不好用. 实现代码 entity.getData()的值:{a ...

  2. getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:

    直接遍历报错:[Ljava.lang.String;@44739f3f Map<String, String> tempMap = new HashMap<String, Strin ...

  3. [C#]List<int>转string[],string[]转为string

    // List<int>转string[] public string[] ListInt2StringArray(List<int> input) { return Arra ...

  4. JSON 与 String、Map、JavaBean互转

    JSON 与 String.Map.JavaBean互转 //解析远程登录用户信息 AttributePrincipal principal = AssertionHolder.getAssertio ...

  5. HDU 4287 Intelligent IME(string,map,stl,make_pair)

    题目 转载来的,有些stl和string的函数蛮好的: //numx[i]=string(sx); //把char[]类型转换成string类型 // mat.insert(make_pair(num ...

  6. JAVA中List转换String,String转换List,Map转换String,String转换Map之间的转换类

    <pre name="code" class="java"></pre><pre name="code" cl ...

  7. Iterator<Entry<String,String>> iter=map.entrySet().iterator(); 是什么意思

    //获得map的迭代器,用作遍历map中的每一个键值对Iterator是迭代器,map之前应该定义过,姑且认为是HashMap.<Entry<String,String>>表示 ...

  8. {}typeof string转为 obj json

    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.3/jquer ...

  9. Jackson将json string转为Object,org.json读取json数组

    从json文件读取json string或者自定义json string,将其转为object.下面采用的object为map,根据map读取json的某个数据,可以读取第一级的数据name,后来发现 ...

  10. POST 发送HTTP请求入参为:String url, Map<String, Object> propsMap

    /** * 发送HTTP请求 * * @param url * @param propsMap * 发送的参数 */ public static String httpSend(String url, ...

随机推荐

  1. C#/.NET/.NET Core技术前沿周刊 | 第 24 期(2025年1.27-1.31)

    前言 C#/.NET/.NET Core技术前沿周刊,你的每周技术指南针!记录.追踪C#/.NET/.NET Core领域.生态的每周最新.最实用.最有价值的技术文章.社区动态.优质项目和学习资源等. ...

  2. 你的边比较松弛:最短路的 Bellman-Ford 和 SPFA 方法

    Dijkstra 的局限性 在带权图的最短路径问题中,我们的目标是从一个起点出发,找到到达其他所有节点的最短路径.无论是交通导航中的最短耗时路线,还是金融网络中的最小成本路径,这一问题的核心始终是如何 ...

  3. RowCellMenuCustomizations 实现 Command 绑定

    给GridControl的行数据单元格添加菜单项,并通过Command绑定的方式实现菜单点击动作触发: <dxg:GridControl x:Name="mainGrid" ...

  4. [开源自荐] Catime 不一样的计时器(番茄时钟),非常欢迎反馈

    Catime 一款简洁的 Windows 倒计时工具,具有透明界面和丰富的自定义选项. Github:https://github.com/vladelaina/Catime 特点 极简设计: 透明界 ...

  5. PowerJob:一款强大且开源的分布式调度与计算框架

      项目名称:PowerJob 项目作者:假诗人 开源许可协议:Apache-2.0 项目地址:https://gitee.com/KFCFans/PowerJob 项目简介 PowerJob(原Oh ...

  6. clickhouse--数据类型

    数据类型 整型 固定长度的整型,包括有符号整型或无符号整型. 整型范围(-2n-1~2n-1-1): Int8 - [-128 : 127] Int16 - [-32768 : 32767] Int3 ...

  7. 介绍一下opentcs

    OpenTCS是一个开源的自动运载系统(Automated Guided Vehicle,AGV)控制系统.它旨在管理和控制自动化运输车辆,例如AGV或自动搬运车(AMR),在工业和商业环境中执行各种 ...

  8. Golang 入门 : 创建第一个Go程序

    创建第一个Go程序 新建一个 helloworld.go 文件,写入以下程序 package main import ( "fmt" ) // 一个函数声明 /* 一个main函数 ...

  9. 搭建自己的OCR服务,第二步:PaddleOCR环境安装

    PaddleOCR环境安装,遇到了很多问题,根据系统不同问题也不同,不要盲目看别人的教程,有的教程也过时了,根据实际情况自己调整. 我这边目前是使用windows 10系统+CPU + python ...

  10. 基于SLAM系统建图仿真,完成定位仿真

    博客地址:https://www.cnblogs.com/zylyehuo/ 基于SLAM系统完成建图仿真,详见之前的博客 基于Gazebo搭建移动机器人,并结合SLAM系统完成建图仿真 - zyly ...