Java String Split by Line splitLines(String text)

Here you can find the source of splitLines(String text)

Description

Split the string in lines; separate by CR, LF or CRLF.

License

Open Source License

Parameter

Parameter Description
text a parameter

Return

list of Strings

Declaration

public static List<String> splitLines(String text) 

Method Source Code

//package com.java2s;
/*//  w  ww.  j a  v a2  s  .com
 * Password Management Servlets (PWM)
 * http://code.google.com/p/pwm/
 *
 * Copyright (c) 2006-2009 Novell, Inc.
 * Copyright (c) 2009-2014 The PWM Project
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class Main {
    /**
     * Split the string in lines; separate by CR, LF or CRLF.
     *
     * @param text
     * @return list of Strings
     */
    public static List<String> splitLines(String text) {
        List<String> list = new ArrayList<>();
        if (text != null) {
            String lines[] = text.split("\r?\n|\r");
            list.addAll(Arrays.asList(lines));
        }
        return list;
    }
}

Related

  1. splitLines(String S)
  2. splitLines(String s)
  3. splitLines(String self)
  4. splitLines(String str, int width)
  5. splitlines(String text)
  6. splitLines(String text)
  7. splitLogLine(final String logLine)
  8. splitMultiline(String text, boolean trimLines)
  9. splitNewLines(final String input)