question: public static List < String > splitText ( String text ) { int startLine = 0 ; int i = 0 ; int n = text . length ( ) ; ArrayList < String > rc = new ArrayList < String > ( ) ; while ( i < n ) { switch ( text . charAt ( i ) ) { case '\n' : i ++ ; if ( i < n && text . charAt ( i ) == '\r' ) { i ++ ; } rc . add ( text . substring ( startLine , i ) ) ; startLine = i ; break ; case '\r' : i ++ ; if ( i < n && text . charAt ( i ) == '\n' ) { i ++ ; } rc . add ( text . substring ( startLine , i ) ) ; startLine = i ; break ; default : i ++ ; } } if ( startLine == text . length ( ) ) { rc . add ( "" ) ; } else { rc . add ( text . substring ( startLine , i ) ) ; } return rc ; }
target:  Split text into lines. New line characters are treated as separators. So if the text starts with newline, empty string will be the first element, if the text ends with new line, the empty string will be the last element. The returned lines will be substrings of the text argument. The new line characters are included into the line text.