【发布时间】:2021-04-21 22:39:13
【问题描述】:
我有 Java 命令行应用程序,我在启动 .jar 文件时使用参数。 参数看起来像
--exclude parent1=child1,child2;parent2=child3;parent3
我想将参数转换为 HashMap<String, String[]> 其中 key=parent1 和 value=[child1,child2]
我尝试使用 Streams 和 split() 函数,但无法将子字符串转换为字符串数组
Arrays.stream(gotData.split(";"))
.map(s -> s.split("="))
.collect(Collectors.toMap(s -> s[0], s -> s[1].split(",")));
【问题讨论】:
标签: java string java-8 java-stream