//list泛型为JSONObject
Map<String, String> map = list.parallelStream().collect(Collectors
.toMap(e -> MapUtils.getString(e, "deviceMac"),
e -> MapUtils.getString(e, "transferRate"), (e1, e2) -> e1));
采用该方法,对于map值为null的情况会在merge时报空指针异常。
可采用下面方式避免创建一个HashMap:
Map<String, String> map=list.stream().collect(HashMap::new,(n,v) -> n.put(v.getId(),v.getName()),HashMap::putAll);