question: public static String [ ] wrapString ( @ Nonnull String str , int maxWidth , @ Nullable String [ ] output ) { if ( output == null ) { output = new String [ ( int ) ( ( str . length ( ) / maxWidth ) * 1.5d + 1 ) ] ; } int lineStart = 0 ; int arrayIndex = 0 ; int i ; for ( i = 0 ; i < str . length ( ) ; i ++ ) { char c = str . charAt ( i ) ; if ( c == '\n' ) { output = addString ( output , str . substring ( lineStart , i ) , arrayIndex ++ ) ; lineStart = i + 1 ; } else if ( i - lineStart == maxWidth ) { output = addString ( output , str . substring ( lineStart , i ) , arrayIndex ++ ) ; lineStart = i ; } } if ( lineStart != i || i == 0 ) { output = addString ( output , str . substring ( lineStart ) , arrayIndex ++ , output . length + 1 ) ; } if ( arrayIndex < output . length ) { output [ arrayIndex ] = null ; } return output ; }
target:  Splits the given string into lines using on any embedded newlines, and wrapping the text as needed to conform to the given maximum line width. <p/> This uses and assumes unix-style newlines