java - divide array into smaller parts -
I want to divide a large byte array into smaller sections (say 64 bytes). Please help me with this.
You can use the method Arrays.copyOfRange (from the original, from)
public static byte [] [] divideArray (byte [] source, int chunksize) {byte [] [] ret = new byte [(int) Math.ceil (source.length / (double) chunksize) ] [ chunk size]; Int start = 0; For (int i = 0; i & lt; ret.length; i ++) {rate = i] = Arrays.copyOfRange (source, start, start + chunksize); Start + = selected; } Return return; }
Or you can suggest Max to the system. Arrecopy
public static byte [] [] divideArray (byte [] source, int chunksize) {byte [] [] rate = new byte [(int) math. Cecil (source length / (double) selective)] [chanaxes]; Int start = 0; For (int i = 0; i & lt; ret.length; i ++) {if (start + chunksize> source.length) {System.arraycopy (source, start, write [i], 0, source Length - start); } Else {System.arraycopy (source, start, write [i], 0, chocex); } Start + = selected; } Return return; }
Comments
Post a Comment