Here you can find the source of splitNewLines(final String input)
public static String[] splitNewLines(final String input)
//package com.java2s; /******************************************************************************* * Copyright (c) 2002, 2010 Innoopract Informationssysteme GmbH. * 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 * * Contributors://from w w w .jav a 2s.c o m * Innoopract Informationssysteme GmbH - initial API and implementation * EclipseSource - ongoing development ******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { public static String[] splitNewLines(final String input) { int length = input.length(); List resultList = new ArrayList(); int start = 0; char last = 0; for (int i = 0; i < length; i++) { char ch = input.charAt(i); if (ch == '\n') { if (last != '\r') { resultList.add(input.substring(start, i)); } start = i + 1; } else if (ch == '\r') { resultList.add(input.substring(start, i)); start = i + 1; } last = ch; } resultList.add(input.substring(start, length)); String[] result = new String[resultList.size()]; resultList.toArray(result); return result; } }