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

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

Description

split

License

Apache License

Declaration

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

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {

    public static String[] split(String str, char separatorChar) {
        if (str == null) {
            return null;
        }/*from w w  w  . j  a v a2 s  .  c o  m*/

        int length = str.length();

        if (length == 0) {
            return new String[0];
        }

        List<String> list = new ArrayList<String>();
        int i = 0;
        int start = 0;

        while (i < length) {
            if (str.charAt(i) == separatorChar) {
                list.add(str.substring(start, i));

                start = ++i;
                continue;
            }
            i++;
        }

        list.add(str.substring(start, i));

        return list.toArray(new String[list.size()]);
    }
}

Related

  1. split(String src, char separator, boolean trim)
  2. split(String str, char separator)
  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)