Below is the example of the code snippet which needs the help
Example:
[1,2,3,4,5]
1
, [1,2,3,4,5]
2
, [1,2]
and [3,4]
and [5]
3
, [1,2,3]
and [4,5]
4
, [1,2,3,4]
and [5]
Java (from comment):
int counter = 0; for (int i=0; i<array.length; i++) { if (count == chunksize) { //do something and initialize counter = 0; } counter++; }
Split() String method in Java with examples. The string split() method breaks a given string around matches of the given regular expression. After splitting against the given regular expression, this method returns a string array.
Using the copyOfRange() method you can copy an array within a range. This method accepts three parameters, an array that you want to copy, start and end indexes of the range. You split an array using this method by copying the array ranging from 0 to length/2 to one array and length/2 to length to other.
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
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<original.length;i+=chunk){ System.out.println(Arrays.toString(Arrays.copyOfRange(original, i, Math.min(original.length,i+chunk)))); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With