I have the following test, test the integers ranging from 0 to max and if it is validated, construct the pair (vals[i], i). Finally, I want to produce a HashMap which uses vals[i] as key and the value is the list of integers. The code looks like,
IntStream.range(0, max)
.parallel()
.filter(i-> sometest(i))
.mapToObj(i -> new Pair<>(vals[i],i))
.collect(groupingBy(Pair::getFirst, mapping(Pair::getSecond, toList())));
My question is, is it possible to use parallel streams to speed up the construction of that map?
Thanks.