Java String Split by Separator split(String str, char separator)

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

Description

split

License

LGPL

Declaration

public static String[] split(String str, char separator) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.List;
import java.util.ArrayList;

public class Main {
    public static String[] split(String str, char separator) {
        if (str == null)
            return null;
        if (str.length() == 0)
            return new String[0];
        List splitList = new ArrayList();
        int startPos = 0;
        int endPos = str.indexOf(separator);
        while (endPos != -1) {
            splitList.add(str.substring(startPos, endPos).trim());
            startPos = endPos + 1;//from   w  ww.ja va 2s .c  om
            endPos = str.indexOf(separator, startPos);
        }
        splitList.add(str.substring(startPos).trim());
        return (String[]) splitList.toArray(new String[splitList.size()]);
    }
}

Related

  1. split(String src, char separator)
  2. split(String src, char separator, boolean trim)
  3. split(String str, char separator)
  4. split(String str, char separator)
  5. split(String str, char separator)
  6. split(String str, char separatorChar)
  7. split(String str, char separatorChar)
  8. split(String str, char separatorChar)
  9. split(String str, char separatorChar)