Here is a Java collection/array to split multiple sub-collections/arrays of two implementations of the notes.
Way One:
/** * Split collection * @param datas * @param splitSize * @param <T> * @return */private <t> list<list<t>> splicearrays ( list<t> datas, int splitsize) { if (datas == null | | &NBSP;SPLITSIZE&NBSP;<&NBSP;1) { return null ; } int totalsize = datas.size (); //gets the number of molecular arrays to be split int count = (totalsize % splitsize == 0) ? (totalsize / splitsize) : (totalsize/splitsize+1); system.out.println ("Split count = " +count"); list<list<t>> rows = new arraYlist (); for (int i = 0;i < count;i ++) { int index = i * splitSize; list<t> cols = new arraylist (); int j = 0; while (j < splitsize && index < totalsize) { cols.add (Datas.get (index++)); j ++; } rows.add (cols); } return rows;}
Way two:
/** * Split collection * @param datas * @param splitSize * @param <T> * @return */private <t> list<list<t>> splicearrays ( list<t> datas, int splitsize) { if (datas == null | | &NBSP;SPLITSIZE&NBSP;<&NBSP;1) { return null ; } int totalsize = datas.size (); int count = (totalsize % splitsize == 0) ? (totalsize / splitsize) : ( TOTALSIZE/SPLITSIZE+1); list<list<t>> rows = new Arraylist<> (); for (int i = 0; i < count;i+ +) &NBSP;{&NBSP;&NBSp; list<t> cols = datas.sublist (i * splitsize, (i == count - 1) ? totalSize : splitSize * (i + 1)); rows.add (cols); system.out.println (cols); } return rows;}
This article is from the "Cocosdev" blog, make sure to keep this source http://xuzhiwei.blog.51cto.com/978424/1740417
Java Array splitting multiple sub-arrays