List<String> (CharSequence chars, final boolean includeSeparators, final boolean skipLastEmptyLine) { if (chars == null || chars.length() == 0){ return Collections.emptyList(); } LineTokenizer tokenizer = new LineTokenizer(chars); List<String> lines = new ArrayList<>(); while(!tokenizer.atEnd()){ int offset = tokenizer.getOffset(); String line; if (includeSeparators){ line = chars.subSequence(offset, offset + tokenizer.getLength() + tokenizer.getLineSeparatorLength()).toString(); } else{ line = chars.subSequence(offset, offset + tokenizer.getLength()).toString(); } lines.add(line); tokenizer.advance(); } if (!skipLastEmptyLine && stringEndsWithSeparator(tokenizer)) lines.add(""); return lines; }