public static MutableList < String > chunk ( String string , int size ) { if ( size <= 0 ) { throw new IllegalArgumentException ( "Size for groups must be positive but was: " + size ) ; } int length = string . length ( ) ; if ( length == 0 ) { return FastList . newList ( ) ; } MutableList < String > result = FastList . newList ( ( length + size - 1 ) / size ) ; int startOffset = 0 ; while ( startOffset < length ) { result . add ( string . substring ( startOffset , Math . min ( startOffset + size , length ) ) ) ; startOffset += size ; } return result ; }
Partitions String in fixed size chunks .