title: How to convert a Java 8 Stream into a two dimensional array?
body: <p>I’m trying to convert a map based <code>Stream</code> into a two-dimensional array. I have figured out how to store it in a one dimensional array. Here is working code snippet:</p>
  
  <pre><code>Float[] floatArray = map.entrySet()
                          .stream()
                          .map(key -&gt; key.getKey().getPrice())
                          .toArray(size -&gt; new Float[size]);
  </code></pre>
  
  <p>When I execute the above code, I get my <code>Float</code> array populated as expected. Now I need to extend this to a two-dimensional array where I need to store the result in first dimension of a 2d array along these lines:</p>
  
  <pre><code>Float[][1] floatArray = map.entrySet()
                             .stream()
                             .map(key -&gt; key.getKey().getPrice())
                             .toArray(size -&gt; new Float[size][1]);
  </code></pre>
  
  <p>The code above does not work. Can you please let me know how to accomplish this task with Java 8 streams? Thanks in advance!</p>