Java String Split by Line splitToLines(CharSequence str)

Here you can find the source of splitToLines(CharSequence str)

Description

split To Lines

License

Open Source License

Declaration

static List<CharSequence> splitToLines(CharSequence str) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    static List<CharSequence> splitToLines(CharSequence str) {
        int pre = 0;
        int length = str.length();
        ArrayList<CharSequence> lines = new ArrayList<CharSequence>(128);

        for (int i = 0; i < length; i++) {
            char c = str.charAt(i);
            if (c == '\n') {
                lines.add(str.subSequence(pre, i));
                //            System.out.println(pre + ", " + i);
                pre = i + 1;/* ww w .j  a  v  a 2  s  .  c  om*/
            }
        }

        if (pre < length) {
            lines.add(str.subSequence(pre, length));
        }

        lines.trimToSize();
        return lines;
    }
}

Related

  1. splitNewLines(final String input)
  2. splitNextWord(String line)
  3. splitString(String line)
  4. splitStringPerWord(String string, int wordsPerLine)
  5. splitter(String line, char delimeter)
  6. splitToLines(final String str)
  7. splitToPairs(String Line)
  8. stringSplit(String line, String delimiter)