Remembering that Java® doesn's actually support 2D arrays; it supports arrays of arrays, which are better . . .
Don't know, but have a few hints:-
1: Indent Streams code differently. Every time you call a method on a Stream after the first call, push the enter key and indent the code so the dots align vertically.2: Use an IDE. If you hover your mouse over the method call you will get a popup with its return type shown e.g. Stream<Foo>. At least that is what Eclipse does, so I expect NetBeans and IntelliJ will have similar functionality.3: Consider not using arrays of primitives; maybe use Double[]s instead.4: I am 99% sure that flatMap takes a Stream<Foo[]> and creates a Stream<Foo>, so it is probably doing the exact opposite of what you want.5: Rather than assigning the arrays in lines 4 and 6, consider printing them with System.out.println(Arrays.deepToString(...6: Use the peek() method to view the contents of your Streams whilst in development for debugging.In your line 4, you are creating a
DoubleStream, which has a
no-args toArray() method returning a
double[]. If you had a Double[] you would be better off the
Stream#toArray() method with a parameter:
myStream.toArray(Double[]::new)
What is wrong with writing a method which takes a
double[] as its parameter and returns a new
double[] with changed values? Call that method with a λ from the map() method.
Actually, by going through by hand and working out the types, there is quite a simple solution and you are not that far off. Here it is
I think a few misspellings have been introduced in copying
but you can retain about half of your line 6 and change the other half.
Addition:-
java LambdaTest
[2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 0.0]
[[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]
[[2.0, 4.0, 6.0], [2.0, 4.0, 6.0]]