Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在分隔符上拆分列表的元素。将原始元素存储为键,将拆分子字符串列表存储为hashmap中的值_Java_Arrays_Collections_Hashmap - Fatal编程技术网

Java 在分隔符上拆分列表的元素。将原始元素存储为键,将拆分子字符串列表存储为hashmap中的值

Java 在分隔符上拆分列表的元素。将原始元素存储为键,将拆分子字符串列表存储为hashmap中的值,java,arrays,collections,hashmap,Java,Arrays,Collections,Hashmap,我有一份清单: “客户活动”、“MRkt客户”、“独立客户账户”、“Opty法案” 我希望分割“389;”上的每个元素,并将原始元素存储为hashmap的键,将分割的元素存储为值 预期结果: {“Cust_Gnrc_活动”:[“Cust”、“Gnrc”、“活动”],“Mrkt_Cust”:[“Mrkt”、“Cust”]}等。大致如下: source.stream() .collect(toMap(Function.identity(), e -> e.split("_")));

我有一份清单:
“客户活动”、“MRkt客户”、“独立客户账户”、“Opty法案”

我希望分割“389;”上的每个元素,并将原始元素存储为hashmap的键,将分割的元素存储为值

预期结果:
{“Cust_Gnrc_活动”:[“Cust”、“Gnrc”、“活动”],“Mrkt_Cust”:[“Mrkt”、“Cust”]}
等。

大致如下:

source.stream()
      .collect(toMap(Function.identity(), e -> e.split("_"))); // Map<String, String[]>
source.stream()
.collect(toMap(Function.identity(),e->e.split(“”));//地图
或者,如果希望将值作为
列表

source.stream()
.collect(toMap(Function.identity()),
e->Arrays.stream(e.split(“”))
.collect(toList());//地图

大致如下:

source.stream()
      .collect(toMap(Function.identity(), e -> e.split("_"))); // Map<String, String[]>
source.stream()
.collect(toMap(Function.identity(),e->e.split(“”));//地图
或者,如果希望将值作为
列表

source.stream()
.collect(toMap(Function.identity()),
e->Arrays.stream(e.split(“”))
.collect(toList());//地图

您可以使用流API执行此操作:

list.stream() // stream over List
        // split by "_" and convert it to List<String>
        .collect(Collectors.toMap(s -> s, s -> Arrays.asList(s.split("_"))));

您可以使用流API执行此操作:

list.stream() // stream over List
        // split by "_" and convert it to List<String>
        .collect(Collectors.toMap(s -> s, s -> Arrays.asList(s.split("_"))));
试着用这个:

Map<String, List<String>> result = new HashMap<>();
list.forEach(str -> result.put(str, Arrays.asList(str.split("_"))));
试着用这个:

Map<String, List<String>> result = new HashMap<>();
list.forEach(str -> result.put(str, Arrays.asList(str.split("_"))));