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

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

Description

split

License

LGPL

Declaration

public static List<String> split(String str, char cha) 

Method Source Code


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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> split(String str, char cha) {
        System.out.println(str + ":" + cha);
        List<String> list = new ArrayList<String>();
        StringBuffer sbf = new StringBuffer(str);
        StringBuffer newSbf = new StringBuffer("");
        for (int i = 0; i < sbf.length(); i++) {
            char c = sbf.charAt(i);
            if (c == cha) {
                list.add(newSbf.toString());
                newSbf.delete(0, newSbf.length());
            } else {
                newSbf.append(c);/*w  w w .  j a v  a  2 s . c om*/
            }
            if (i == sbf.length() - 1) {
                list.add(newSbf.toString());
            }
        }
        return list;
    }
}

Related

  1. split(String str, char c)
  2. split(String str, char c)
  3. split(String str, char ch)
  4. split(String str, char ch)
  5. split(String str, char ch, int size)
  6. split(String str, char deli)
  7. split(String str, char sep)
  8. split(String str, char splitChar)
  9. split(String str, char splitChar)