collect() — accumulates into a collection (List, Set, Map, etc.). toArray() — converts to a fixed-size array. Think of collect() as filling a flexible toolbox, while toArray() as packing items into a fixed-size crate.
collect():
Collector.1List<String> list = stream.collect(Collectors.toList());2Set<Integer> set = stream.collect(Collectors.toSet());3Map<String, Integer> map = stream4 .collect(Collectors.toMap(s -> s, String::length));
toArray():
Object[] or typed array.1Object[] arr = stream.toArray();2String[] arr = stream.toArray(String[]::new);
Key difference:
Performance considerations: