Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
9 Collecting Results
• When you are done with a stream, you often just want
to look at the results instead of reducing them to a
value.
• You can call toArray and get an array of the stream
elements.
• Since it is not possible to create a generic array at
runtime, the expression stream.toArray() returns an
Object[] array.
• If you want an array of the correct type, pass in the
array constructor:
• String[] result = words.toArray(String[]::new); //
words.toArray() has type Object[]
2.9 Collecting Results