Is .collect guaranteed to be ordered on parallel streams?
问题 Given I have a list of Strings List<String> toProcess . The results have to be in the order the original lines were given. I want to utilize the new parallel streams. Does the following code guarantee that the results will be in the same order they were in the original list? // ["a", "b", "c"] List<String> toProcess; // should be ["a", "b", "c"] List<String> results = toProcess.parallelStream() .map(s -> s) .collect(Collectors.toList()); 回答1: TL;DR Yes, the order is guaranteed. Stream.collect