Java String Split by Line splitLines(String self)

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

Description

split Lines

License

Open Source License

Declaration

public static List splitLines(String self) 

Method Source Code


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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List splitLines(String self) {
        List lines = new ArrayList<String>(16);
        int len = self.length();
        int s = 0;
        for (int i = 0; i < len; ++i) {
            int c = self.charAt(i);
            if (c == '\n' || c == '\r') {
                lines.add(self.substring(s, i));
                s = i + 1;/*  w ww. j  a va2s  .  co m*/
                if (c == '\r' && s < len && self.charAt(s) == '\n') {
                    i++;
                    s++;
                }
            }
        }
        lines.add(self.substring(s, len));
        return lines;
    }
}

Related

  1. splitLines(final String helpMessage)
  2. splitLines(final String string)
  3. splitLines(String raw, int limit)
  4. splitLines(String S)
  5. splitLines(String s)
  6. splitLines(String str, int width)
  7. splitlines(String text)
  8. splitLines(String text)
  9. splitLines(String text)