Java String Explode explode(String src, String sep)

Here you can find the source of explode(String src, String sep)

Description

explode

License

Open Source License

Declaration

public static String[] explode(String src, String sep) 

Method Source Code


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

import java.util.ArrayList;

public class Main {
    public static String[] explode(String src, String sep) {
        if (src == null) {
            return null;
        }/*  ww w  .j  a  v  a2  s  .c  om*/

        ArrayList<String> outputTmp = new ArrayList<String>();
        char[] buffer = src.toCharArray();
        char[] delimiter = sep.toCharArray();

        boolean separate = false;
        int start = 0;

        for (int i = 0; i < buffer.length; i++) {
            if (buffer[i] == delimiter[0]) {
                separate = true;

                if (i + delimiter.length <= buffer.length) {
                    for (int j = 1; j < delimiter.length; j++) {
                        if (buffer[i + j] != delimiter[j]) {
                            separate = false;
                            break;
                        }
                    }
                    if (separate) {
                        outputTmp.add(new String(buffer, start, i - start));
                        i += delimiter.length - 1;
                        start = i + 1;
                    }
                }
            }
        }

        outputTmp.add(new String(buffer, start, buffer.length - start));
        return outputTmp.toArray(new String[0]);
    }
}

Related

  1. explode(String handleStr, String pointStr)
  2. explode(String input, final char delimiter, final char escape, final int capacity)
  3. explode(String s, String delim)
  4. explode(String source, String deliminator)
  5. explode(String split, String input)
  6. explode(String string, String separators)
  7. explode(String tokenizer, String text)
  8. explode(String[] elements, String separator)
  9. explodeCamelCase(String str, boolean excludeGetOrSet)