String转Map集合
1.参数类型 {key=value, key=value, key=value}
2.转为Map<String,String>
2.1常规写法
private Map<String,String> sendStringToMap(String send){
String strip = StringUtils.strip(send, "{}"); String[] split = strip.split(","); List<String> list = Arrays.asList(split);
return list.stream().map(item -> item.split("=")).collect(Collectors.toMap(i -> i[0].trim(), i -> i[1]));
}
2.2简洁写法
private Map<String,String> sendStringToMap(String send){ return Arrays.stream( StringUtils.strip(send, "{}") .split(",")).map(item -> item.split("=")).collect(Collectors.toMap(i -> i[0].trim(), i -> i[1])); }
3.用到的包(StringUtils)
<dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency>