How to collect result of a stream into an array of custom object in Java 8 [duplicate]
问题 This question already has answers here : How to convert a Java 8 Stream to an Array? (9 answers) Java stream toArray() convert to a specific type of array (2 answers) Closed 8 months ago . I have an List<TestBuilder> testBuilders; Test has a function build of type Test I did testBuilders.stream().map(Test::build()).collect() I want to collect above in array of Test i.e Test[] I am not sure what would go in collect function 回答1: Use the terminal operation Stream::toArray which packs the