I have the following code reading lines from a text file:
try (BufferedReader br = new BufferedReader(new InputStreamReader(Uio.decodeFrom(url)))) {
return br.lines()
.parallel()
.map(s -> s.split("\\s+")) // split by whitespace
.collect(
Collectors.groupingByConcurrent(
arr -> arr[0], // String 1
Collectors.groupingByConcurrent(
arr -> arr[arr.length-1], // String 2
Collectors.counting()
)
)
);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
The text file has data like
String1 ... cols ... String2
string1data ... otherdata ... string2data
...
And I'm trying to group by String1 and String2 and get their counts. Then end result should be a Map<String, Map<String, Long>>. However, with the code above, the compiler is saying that the collect() returns a ConcurrentMap <Object, ConcurrentMap<Object, Long>>.
Why are the keys not Strings?