Here you can find the source of splitToLines(CharSequence str)
static List<CharSequence> splitToLines(CharSequence str)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { static List<CharSequence> splitToLines(CharSequence str) { int pre = 0; int length = str.length(); ArrayList<CharSequence> lines = new ArrayList<CharSequence>(128); for (int i = 0; i < length; i++) { char c = str.charAt(i); if (c == '\n') { lines.add(str.subSequence(pre, i)); // System.out.println(pre + ", " + i); pre = i + 1;/* ww w .j a v a 2 s . c om*/ } } if (pre < length) { lines.add(str.subSequence(pre, length)); } lines.trimToSize(); return lines; } }