Here you can find the source of splitLine(String s, boolean removeNewLine)
public static String[] splitLine(String s, boolean removeNewLine)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014,2015 Hideki Yatomi * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ import java.util.*; public class Main { public static String[] splitLine(String s, boolean removeNewLine) { s = normalizeNewLine(s);/*from w w w .j a v a2 s . c o m*/ StringTokenizer tk = new StringTokenizer(s, "\n", true); String[] array = new String[tk.countTokens()]; for (int i = 0; i < array.length; i++) { array[i] = tk.nextToken(); } List<String> list = new ArrayList<>(); for (int i = 0; i < array.length; i++) { String e = array[i]; if (i < array.length - 1 && !e.equals("\n")) { String next = array[i + 1]; if (next.equals("\n")) { e += next; i++; } } if (removeNewLine) e = e.replace("\n", ""); list.add(e); } return list.toArray(new String[list.size()]); } public static String normalizeNewLine(String s) { s = s.replace("\r\n", "\n"); s = s.replace("\r", "\n"); return s; } }