First and foremost the reason why your code doesn't work is because there's no such method mapToFloat in the Java API but most importantly there is no FloatStream.
your options are quite limited if you want to accomplish this via streams:
- accumulate to a
Float[][] instead of a float[][], which might not be ideal as it involves boxing and unboxing bottleneck when you want to perform some computation later on in your application.
this can be accomplished via:
Float[][] trainingData = lists.stream()
.map(l -> l.toArray(new Float[0]))
.toArray(Float[][]::new);
- use a
List<List<Double>> in the first place rather than a List<List<Float>>to represent your training data, then you can just convert it to a double[][] when required:
this can be accomplished via:
double[][] trainingData = lists.stream()
.map(l -> l.stream().mapToDouble(Double::doubleValue).toArray())
.toArray(double[][]::new);
but if you cannot change the initial type of data for whatever reasons then you can still covert to a double[][].
this can be accomplished via:
double[][] trainingData = lists.stream()
.map(l -> l.stream().mapToDouble(Float::doubleValue).toArray())
.toArray(double[][]::new);
- define your own
Collector which you should be able to find within the site with some research.
Ultimately you're probably better off using an imperative approach here i.e. for loops.