Java String Split by Separator split(CharSequence seq, char separator)

Here you can find the source of split(CharSequence seq, char separator)

Description

split

License

Open Source License

Declaration

public static List<String> split(CharSequence seq, char separator) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    private static final char ESCAPE_CHAR = '\\';

    public static List<String> split(CharSequence seq, char separator) {
        List<String> strs = new ArrayList<>();
        StringBuilder buffer = new StringBuilder();
        int index = 0;
        while (index < seq.length()) {
            char ch = seq.charAt(index++);
            if (ch == ESCAPE_CHAR) {
                if (index < seq.length())
                    buffer.append(seq.charAt(index++));
            } else if (ch == separator) {
                strs.add(buffer.toString());
                buffer.setLength(0);/*from  w w w.j ava 2s .com*/
            } else
                buffer.append(ch);
        }
        strs.add(buffer.toString());

        return strs;
    }
}

Related

  1. fastSplit(final String text, char separator)
  2. fastSplit(String text, char separator)
  3. split(byte[] b, int separator)
  4. split(final String expression, final char separator)
  5. split(final String input, final String separator)
  6. split(final String iSource, final char iRecordSeparator, final char... iJumpCharacters)
  7. split(final String s, final char separator)