Below is the example of the code snippet which needs the help
Example:
[1,2,3,4,5]
if the chunk size is 1, [1,2,3,4,5]
if the chunk size is 2, [1,2] and [3,4] and [5]
if the chunk size is 3, [1,2,3] and [4,5]
if the chunk size is 4, [1,2,3,4] and [5]
Java (from comment):
int counter = 0;
for (int i=0; i
if (count == chunksize) {
//do something and initialize
counter = 0;
}
counter++;
}
解决方案
You can use Arrays.copyOfRange(int[] original, int from, int to)
The code could be something like this:
int chunk = 2; // chunk size to divide
for(int i=0;i
System.out.println(Arrays.toString(Arrays.copyOfRange(original, i, Math.min(original.length,i+chunk))));
}