use of one.util.streamex.Internals.FloatBuffer in project streamex by amaembo.
the class DoubleStreamEx method toFloatArray.
/**
* Returns a {@code float[]} array containing the elements of this stream
* which are converted to floats using {@code (float)} cast operation.
*
* <p>
* This is a terminal operation.
*
* @return an array containing the elements of this stream
* @since 0.3.0
*/
public float[] toFloatArray() {
if (isParallel())
return collect(DoubleCollector.toFloatArray());
java.util.Spliterator.OfDouble spliterator = spliterator();
int size = intSize(spliterator);
FloatBuffer buf;
if (size >= 0) {
buf = new FloatBuffer(size);
spliterator.forEachRemaining((DoubleConsumer) buf::addUnsafe);
} else {
buf = new FloatBuffer();
spliterator.forEachRemaining((DoubleConsumer) buf::add);
}
return buf.toArray();
}
Aggregations