question: public static < T > List < T > [ ] split ( Collection < T > set , double [ ] weights ) { if ( set . size ( ) >= weights . length ) { @ SuppressWarnings ( "unchecked" ) List < T > [ ] arrays = new List [ weights . length ] ; double totalweight = 0.0 ; for ( double w : weights ) totalweight += w ; double [ ] relativeWeight = new double [ weights . length ] ; for ( int i = 0 ; i < weights . length ; i ++ ) relativeWeight [ i ] = weights [ i ] / totalweight ; int [ ] listSizes = new int [ weights . length ] ; for ( int i = 0 ; i < weights . length ; i ++ ) listSizes [ i ] = ( int ) ( weights [ i ] / totalweight * ( double ) set . size ( ) ) ; int allocated = 0 ; for ( int ls : listSizes ) allocated += ls ; int remainder = set . size ( ) - allocated ; listSizes [ 0 ] += remainder ; Iterator < T > it = set . iterator ( ) ; for ( int i = 0 ; i < listSizes . length ; i ++ ) { List < T > segment = new ArrayList < > ( listSizes [ i ] ) ; for ( int k = 0 ; k < listSizes [ i ] ; k ++ ) { segment . add ( it . next ( ) ) ; } arrays [ i ] = segment ; } return arrays ; } else { throw new IllegalArgumentException ( "weigths.length must not be smaller than set size!" ) ; } }
target:  Split the collection into weights.length