Java String Split by Delimiter split(String a, String delim)

Here you can find the source of split(String a, String delim)

Description

split

License

Open Source License

Declaration

public static String[] split(String a, String delim) 

Method Source Code

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

public class Main {

    public static String[] split(String a, String delim) {

        if ("".equals(a))
            return new String[0];

        int position = 0;
        int delimiterIdx = 0;
        int strLen = a.length();
        List<String> resultList = new ArrayList<String>();

        int len = delim.length();
        while (position <= strLen) {
            delimiterIdx = a.indexOf(delim, position);
            if (delimiterIdx > -1) {
                resultList.add(a.substring(position, delimiterIdx));
            } else {
                resultList.add(a.substring(position, strLen));
                break;
            }//  w w w .j  a  v  a  2 s.co  m
            position = delimiterIdx + len;
        }

        return (String[]) resultList.toArray(new String[] {});
    }
}

Related

  1. split(final String input, final char delimiter)
  2. split(final String input, final String delimiter, final boolean removeEmpty)
  3. split(final String src, final char delim)
  4. split(final String str, final char delim)
  5. split(final String str, final String delimiter)
  6. split(String input, char delimiter)
  7. split(String input, String delimiter)
  8. split(String input, String delimiter)
  9. split(String input, String... delimiters)