Java String Split by Delimiter split(String str, String delimiter)

Here you can find the source of split(String str, String delimiter)

Description

split

License

Open Source License

Declaration

public static String[] split(String str, String delimiter) 

Method Source Code


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

public class Main {
    public static String[] split(String str, String delimiter) {
        ArrayList list = new ArrayList();
        int idx = 0;
        while (true) {
            idx = str.indexOf(delimiter);
            if (idx == -1) {
                list.add(str);//from w  w  w  .j a  v a2 s . c  o  m
                break;
            }
            list.add(str.substring(0, idx));
            str = str.substring(idx + delimiter.length());
        }
        return (String[]) list.toArray(new String[list.size()]);
    }
}

Related

  1. split(String str, String delim)
  2. split(String str, String delimeter)
  3. split(String str, String delimiter)
  4. split(String str, String delimiter)
  5. split(String str, String delimiter)
  6. split(String str, String delimiter)
  7. split(String str, String delimiter, int limit)
  8. split(String str, String delims)
  9. split(String str, String regexDelim, int limitUseRegex)