我正在尝试将
JSONArray转换为Map< String,String>通过溪流和Lambdas.以下不起作用:
org.json.simple.JSONArray jsonArray = new org.json.simple.JSONArray();
jsonArray.add("pankaj");
HashMap stringMap = jsonArray.stream().collect(HashMap::new, (map,membermsisdn) -> map.put((String)membermsisdn,"Error"), HashMap::putAll);
HashMap stringMap1 = jsonArray.stream().collect(Collectors.toMap(member -> member, member -> "Error"));
为了避免在第4行进行类型转换,我正在进行第3行
第3行出现以下错误:
Multiple markers at this line
- The type HashMap does not define putAll(Object, Object) that is applicable here
- The method put(String, String) is undefined for the type Object
- The method collect(Supplier, BiConsumer, BiConsumer) in the type Stream is not applicable for the arguments (HashMap::new, ( map, membermsisdn)
-> {}, HashMap::putAll)
第4行出现以下错误:
Type mismatch: cannot convert from Object to HashMap
我正在努力学习Lambdas和溪流.有人可以帮帮我吗?