Java String Split by Char split(String str, char sep)

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

Description

split

License

LGPL

Declaration

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

Method Source Code

//package com.java2s;
/*//from   w ww . ja v  a  2  s  .  c  om
 * MoXie (SysTem128@GMail.Com) 2009-3-11 10:06:36
 * 
 * Copyright © 2008-2009 Zoeey.Org
 * Code license: GNU Lesser General Public License Version 3
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 */

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

public class Main {

    public static String[] split(String str, char sep) {
        if (str == null) {
            return new String[0];
        }
        int length = str.length();
        char ch = 0;
        List<String> strList = new ArrayList<String>();
        StringBuilder strBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            ch = str.charAt(i);
            if (ch == sep) {
                strList.add(strBuilder.toString());
                strBuilder = new StringBuilder();
            } else {
                strBuilder.append(ch);
            }
        }
        strList.add(strBuilder.toString());
        strBuilder = null;
        return strList.toArray(new String[strList.size()]);
    }
}

Related

  1. split(String str, char ch)
  2. split(String str, char ch)
  3. split(String str, char ch, int size)
  4. split(String str, char cha)
  5. split(String str, char deli)
  6. split(String str, char splitChar)
  7. split(String str, char splitChar)
  8. Split(String Str, char splitchar)
  9. split(String string, char c)