title: Creating an array of subarrays by slicing a bigger array into chunks (Java)
body: <p>I am trying to make a method that given an array and k (number of subarrays we want to divide it into), it will divide the said array into that number of subarrays. I made this so far:</p>
  <pre><code>   public static int[][] slice(int[] arr, int k) {
       int i, j;
       int arrLength = arr.length;
       double divided = arrLength / k;
       int evenOdd = arrLength % k;
       int chunks = (int) Math.ceil((double) arrLength / k);
  
       int[][] output = IntStream.iterate(0, l -&gt; l + chunks)
         .limit((int) Math.ceil((double) arr.length / chunks))
         .mapToObj(m -&gt; Arrays.copyOfRange(arr, m, Math.min(arr.length, m + chunks)))
         .toArray(int[][]::new);
  
       return output;
     }
  </code></pre>
  <p>However, this only works when the variable k is smaller or equal to half the size of the array we give. For example, if I give the arr {1,2,3,4,5,6,7} and choose k=5, it still separates my array into 4 subarrays.</p>
  <p>Does anyone know how to fix this? Thanks very much in advance.</p>