I have a file where each line is a pipe-delimitted string of float values. I am reading the file line by line and splitting by "|" and then casting each element to a float. I can use Java streams to get this as a Float array, but I want to know if it is possible to get this as the primitive float[] array. The reason being is that I am passing these values into a library which expects float[].
Here is my code:
br = Files.newBufferedReader(Paths.get(inputFile));
String[] lines = br.lines().toArray(String[]::new);
for(String line : lines) {
Float[] inputs =
Arrays.stream(line.split("|"))
.map((x) -> Float.parseFloat(x))
.toArray(Float[]::new);
}
Is there a way to use streams to get a primitive float[] array, or do I still need to iterate over the Float[] and convert? I looked into DoubleStream, but I can't have a double[].
Thanks
EDIT: thanks for all comments. Ended up iterating over Float[] and calling .floatValue on each element and storing the value in a float[].