title: How to initialize generic array?
body: <p>This method is used to split array into chunks <a href="https://stackoverflow.com/a/39788851/6891563">reference</a>. I want to make this method generic. </p>
  
  <p><strong>Problem</strong> is, I can not initialize array like this.</p>
  
  <pre><code>T[][] arrays = new T[chunks][];
  </code></pre>
  
  <p>complete method  </p>
  
  <pre><code> public &lt;T&gt; T[][] splitArray(T[] arrayToSplit, int chunkSize) {
          if (chunkSize &lt;= 0) {
              return null;
          }
          int rest = arrayToSplit.length % chunkSize;
          int chunks = arrayToSplit.length / chunkSize + (rest &gt; 0 ? 1 : 0);
          T[][] arrays = new T[chunks][];
          for (int i = 0; i &lt; (rest &gt; 0 ? chunks - 1 : chunks); i++) {
              arrays[i] = Arrays.copyOfRange(arrayToSplit, i * chunkSize, i * chunkSize + chunkSize);
          }
          if (rest &gt; 0) {
              arrays[chunks - 1] = Arrays.copyOfRange(arrayToSplit, (chunks - 1) * chunkSize, (chunks - 1) * chunkSize + rest);
          }
          return arrays;
      }
  </code></pre>
  
  <p>What is correct way to initialize generic array?</p>