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;
}

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 ; }
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 .
