流的使用之“如何将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. 超详细,DeepSeep 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方DeepSeek接入),建议收藏!

    在当今数字化时代,AI编程助手已成为提升开发效率的利器.DeepSeek作为一款强大的AI模型,凭借其出色的性能和开源免费的优势,成为许多开发者的首选.今天,就让我们一起探索如何将DeepSeek接入 ...

  2. 满血 DeepSeek 现可无需等待免费使用暨第三方 API 平台横评

    亮点:高可用的 API 平台,新人免费 100 万 token ,DeepSeek-R1 (671B)与 DeepSeek-V3 模型享五折优惠,活动时间为2025年02月12日18:00:00~20 ...

  3. thymeleaf 使用th:onclick传递参数问题:

    使用方法:注意:传递参数时如果参数是数字这样写没有问题,但是如果参数是字符串onclick的方法将无法接收到参数并报错,所以参数是字符串时要加单引号.如上图.

  4. 常见的各类LLM基座模型(GPT、DeepSeek、Qwen等)模型解析以及对比

    From: https://www.big-yellow-j.top/posts/2025/02/15/LLM.html 各类LLM模型技术汇总 只去对比整体框架,对所采用的激活函数,归一化处理,位置 ...

  5. layui 自动触发radio和select

    layui对radio和select做了包装,正常用jquery选中后使用trigger不起作用. 那么,怎么让其自动触发呢? 对radio来说,必须在$选中后.next('.layui-form-r ...

  6. 探秘Transformer系列之(10)--- 自注意力

    探秘Transformer系列之(10)--- 自注意力 目录 探秘Transformer系列之(10)--- 自注意力 0x00 概述 0x01 原理 1.1 设计思路 1.2 输入 1.3 QKV ...

  7. 【文献阅读】 PVDF &阻尼&有限元建模

    1. 压电Damper原理 Piezoelectric Composite Materials - ScienceDirect 当振动传递到压电材料时,振动能量通过压电效应转化为电能,产生交流电压.所 ...

  8. linux npm 全局安装 command not found

    前言 在 linux 使用 npm 全局安装一个模块时,会提示命令找不到. 例如:npm install @quasar/cli -g 后 $ quasar -v quasar: command no ...

  9. HTTP内容编码和HTTP压缩的区别

    HTTP压缩,在HTTP协议中,其实是内容编码的一种. 在http协议中,可以对内容(也就是body部分)进行编码, 可以采用gzip这样的编码. 从而达到压缩的目的. 也可以使用其他的编码把内容搅乱 ...

  10. Linux下启动Oracle命令

    1.进入LInux,切换到Oracle用户权限,输入数据库密码.su - oracle    1在这里插入图片描述2.输入sqlplus "/as sysdba"    1在这里插 ...