Here you can find the source of getLines(String str)
public static List<String> getLines(String str)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { /**//from w w w .ja v a 2 s. c om * Returns all lines from the given string, i.e. the text between newline characters and start and end of the string. * Also parses empty lines as new lines, e.g. the String "\n\n" yields three empty lines. */ public static List<String> getLines(String str) { String line = null; List<String> lines = new ArrayList<>(); if (str.isEmpty()) { lines.add(""); return lines; } // if (str.startsWith("\n") || str.startsWith("\r\n")) // lines.add(""); Scanner scanner = new Scanner(str); while (scanner.hasNextLine()) { line = scanner.nextLine(); lines.add(line); } scanner.close(); if (str.endsWith("\n") || str.endsWith("\r\n")) lines.add(""); return lines; } }