First of all, the corresponding excerpt from the documentation Collectors.toList():
[...] , , ; , toCollection ()
characteristics; :
public static final Collector.Characteristics CONCURRENT
, , , , .
CONCURRENT UNORDERED, , .
, , Collectors.toList(), Concurrent .
, , , , , . , , , javadoc. , :
.collect(
Collector.of(CopyOnWriteArrayList::new,
List::add,
(o, o2) -> { o.addAll(o2); return o; },
Function.<List<String>>identity(),
Collector.Characteristics.CONCURRENT,
Collector.Characteristics.IDENTITY_FINISH
)
)
.
. .
, Stream ( {Int, Double, Long} Stream, ) AutoCloseable. , I/O Files.lines() - .
, :
final List<MyClass> list;
try (
final Stream<String> lines = Files.lines(...);
) {
list = lines.parallel().map(MyClass::new)
.collect(seeAbove);
}