I have an original list and i am using parallel processing on that list(calling a method). What is want is to store the response of that method to a new list in the same order as the original list.
public List<XYZResponse> process(List<String> inputs) {
List<XYZResponse> myResponse = new ArrayList<>();
inputs.parallelStream().forEach(input -> {
myResponse.add(processStringInput(input));
});
}
return myResponse;
}
private XYZResponse processStringInput(String input) {
return new XYZResponse.Builder().resp(input).build();
}
Here i want my List to be in the same order as the inputs Array. Have tried a few other answers from stack overflow, but with no luck. Any help is appreciated.