@ SuppressWarnings ( "unchecked" ) public < A > A [ ] toArray ( Class < A > elementClass ) { return stream ( ) . toArray ( size -> ( A [ ] ) Array . newInstance ( elementClass , size ) ) ; }
Returns an array containing all the stream elements using the supplied element type class to allocate an array .