Title, the sample code is as follows:
/*** 1> by number of copies---list *@paramSource *@paramHow many copies num wants to divide into *@return */ Public Static<T> list<list<t>> Splitlistfornum (list<t> source,intnum) {List<List<T>> result=NewArraylist<list<t>>(); intRemaider=source.size ()%num;//(the remainder is calculated first) intNumber=source.size ()/num;//then the business intoffset=0;//Offset Amount for(inti=0;i<num;i++) {List<T> value=NULL; if(remaider>0) {Value=source.sublist (I*number+offset, (i+1) *number+offset+1); Remaider--; Offset++; }Else{Value=source.sublist (I*number+offset, (i+1) *number+offset); } result.add (value); } returnresult; } /*** 2> According to target capacity list *@paramSource *@paramcapacity dividing the completed single list capacity *@param<T> *@return */ Public Static<T> list<list<t>> splitlistbycapacity (list<t> source,intcapacity) {List<List<T>> result=NewArraylist<list<t>>(); if(Source! =NULL){ intSize =source.size (); if(Size > 0 ){ for(inti = 0; I <size;) {List<T> value =NULL; intEnd = i+capacity; if(End >size) {End=size; } Value=source.sublist (i,end); I=end; Result.add (value); } }Else{result=NULL; } }Else{result=NULL; } returnresult; } Public Static voidMain (string[] args) {List<Integer> all =NewArraylist<>(); intA= 1000; for(inti = 0; i < A; i++) {All.add (i+1); } List<List<Integer>> split = splitlistbycapacity (all,333); System.out.println (Split.size ()); for(list<integer>strings:split) {System.out.println (Strings.size ()); } }
"Java" divides the list into several tool classes of List 1. Divided by target number 2. By Target capacity