Java String Split by Delimiter SplitAt(String s, String delimiter)

Here you can find the source of SplitAt(String s, String delimiter)

Description

Split At

License

Creative Commons License

Declaration

private static String[] SplitAt(String s, String delimiter) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    private static String[] SplitAt(String s, String delimiter) {
        if (delimiter == null || delimiter.length() == 0)
            throw new IllegalArgumentException();
        if (s == null || s.length() == 0)
            return new String[] { "" };
        int index = 0;
        boolean first = true;
        ArrayList<String> strings = null;
        int delimLength = delimiter.length();
        while (true) {
            int index2 = s.indexOf(delimiter, index);
            if (index2 < 0) {
                if (first)
                    return new String[] { s };
                strings.add(s.substring(index));
                break;
            } else {
                if (first) {
                    strings = new ArrayList<String>();
                    first = false;/*  ww  w. j  av a  2s.c om*/
                }
                String newstr = s.substring(index, index2);
                strings.add(newstr);
                index = index2 + delimLength;
            }
        }
        return strings.toArray(new String[] {});
    }
}

Related

  1. split(String what, char delim)
  2. split(String[] srcArray, String delimiterRegExp)
  3. split2(String string, String delimiter)
  4. splitAll(String str, String delim)
  5. splitAndTrim(String string, String delim)
  6. SplitAt(String str, String delimiter)
  7. splitByStr(String s, String delim)
  8. splitChars(String str, String delimiters)
  9. splitFast(String text, char delim)