@ SuppressWarnings ( "unchecked" ) public static < T > T [ ] randomArrayFrom ( Supplier < T > elementSupplier , int size ) { checkArgument ( size >= 0 , "Size must be greater than or equal to zero" ) ; return ( T [ ] ) Stream . generate ( elementSupplier ) . limit ( size ) . toArray ( Object [ ] :: new ) ; }
Returns an array filled from the given element supplier .