public static < T > List < List < T > > splitList ( List < T > _list , int _elements ) { List < List < T >> partitions = new ArrayList <> ( ) ; for ( int i = 0 ; i < _list . size ( ) ; i += _elements ) { partitions . add ( _list . subList ( i , Math . min ( i + _elements , _list . size ( ) ) ) ) ; } return partitions ; }
Split a List into equal parts . Last list could be shorter than _elements .