title: Convert nested list to 2d array
body: <p>I'm trying to convert a nested list into a 2d array.</p>
  
  <pre><code>List&lt;List&lt;String&gt;&gt; list = new ArrayList&lt;&gt;();
  
  list.add(Arrays.asList("a", "b", "c"));
  list.add(Arrays.asList("dd"));
  list.add(Arrays.asList("eee", "fff"));
  </code></pre>
  
  <p>I want to make this a <code>String[][]</code>. I've tried the following:</p>
  
  <pre><code>String[][] array = (String[][]) list.toArray();      // ClassCastException
  
  String[][] array = list.toArray(new String[3][3]);   // ArrayStoreException
  
  String[][] array = (String[][]) list.stream()        // ClassCastException
      .map(sublist -&gt; (String[]) sublist.toArray()).toArray();
  </code></pre>
  
  <p>Is there a way that works? Note that I won't know the size of the list until runtime, and it may be jagged.</p>