I have code like this:
ArrayList<Map<String, String>> resultArray = resultList.stream() //
.map(parser::parseJson) //
.filter(ev -> ev.entrySet().containsAll(filter.entrySet())) //
.collect(Collectors.toCollection(ArrayList::new));
The caller resultList is an ArrayList, which is an array of JSON(s). I want to parse each element into map, filter the map, and collect the arrays of maps.
The code in the above line has no complier error. But at runtime it gives error as:
Error:(51, 25) java: incompatible types: cannot infer type-variable(s)
R,A,capture#1 of ?,T,C,E (argument mismatch;
java.util.stream.Collector<java.util.Map<java.lang.String,java.lang.String>,capture#2 of
?,java.util.ArrayList<java.util.Map<java.lang.String,java.lang.String>>
> cannot be converted to java.util.stream.Collector<? super
java.util.Map,capture#2 of
?,java.util.ArrayList<java.util.Map<java.lang.String,java.lang.String>>
>)
I've tried many different ways like Collectors.toList() but it doesn't work. I'm still after a clean solution for parsing each String element to map and collecting all of them as an ArrayList.
Update: the parser is from com.json.parsers.JSONParser;
parser::parseJson? can improve toList<Map<String, String>> resultArrayas well.