Java Utililty Methods String Split by Char

List of utility methods to do String Split by Char

Description

The list of methods to do String Split by Char are organized into topic(s).

Method

String[]splitChars(String input, String charsToBeRemoved)
Split the input string considering as string separator the chars specified in the input variable charsToBeRemoved.
ArrayList output = new ArrayList();
int minCapacity = 0;
StringBuffer str = new StringBuffer();
boolean charFound = false;
boolean toBeAdd = false;
for (int index = 0; index < input.length(); index++) {
    charFound = false;
    for (int charsCount = 0; charsCount < charsToBeRemoved.length(); charsCount++)
...
ArrayListsplitEncolosed(String s, char open_tag, char close_tag)
split Encolosed
ArrayList<String> ret = new ArrayList<String>();
char[] chars = s.toCharArray();
String contents = "";
for (char c : chars) {
    if (c == open_tag) {
        if (!contents.isEmpty()) {
            ret.add(contents);
        contents = "";
    } else if (c == close_tag) {
        ret.add(contents);
        contents = "";
    } else {
        contents += c;
if (!contents.isEmpty()) {
    ret.add(contents);
    contents = "";
return ret;
String[]splitFast3(String data, char splitChar)
split Fast
if (data == null) {
    return new String[0];
List<String> result = new ArrayList<String>();
int last = 0;
int dataLength = data.length();
for (int i = 0; i < dataLength; i++) {
    if (data.charAt(i) == splitChar) {
...
String[]splitInclusive(CharSequence input, char[] splitChars)
split Inclusive
ArrayList<String> splited = new ArrayList<>();
String readthusfar = "";
for (int i = 0; i < input.length(); i++) {
    char readChar = input.charAt(i);
    if (containsChar(splitChars, readChar)) {
        if (!readthusfar.isEmpty()) {
            splited.add(readthusfar);
            readthusfar = "";
...
ListsplitList(String source, char useChar)
split List
List list = new ArrayList();
String sub;
if (source.charAt(0) == useChar)
    source = source.substring(1, source.length());
if (source.charAt(source.length() - 1) == useChar)
    source = source.substring(0, source.length() - 1);
int start = 0;
int end = source.indexOf(useChar);
...
String[]splitOnChar(String str, char c)
split On Char
ArrayList<String> result = new ArrayList<String>();
int lastOffset = 0;
int curOffset;
while ((curOffset = str.indexOf(c, lastOffset)) != -1) {
    result.add(str.substring(lastOffset, curOffset));
    lastOffset = curOffset + 1;
result.add(str.substring(lastOffset));
...
String[]splitOnChar(String str, int ch)
A faster way to split on a single char than String#split(), since we'll be doing this in a tight loop possibly thousands of times (rt.jar).
List<String> list = new ArrayList<String>(3);
int pos = 0;
int old = 0;
while ((pos = str.indexOf(ch, old)) > -1) {
    list.add(str.substring(old, pos));
    old = pos + 1;
list.add(str.substring(old));
...
String[]splitOnCharArray(String value, String splitOn)
split On Char Array
ArrayList<String> pointPairs = new ArrayList<String>();
int i;
int prev = 0;
for (i = 0; i < value.length(); i++) {
    if (splitOn.indexOf(value.charAt(i)) != -1) {
        pointPairs.add(value.substring(prev, i));
        while (i < value.length() && splitOn.indexOf(value.charAt(i)) != -1) {
            i++;
...
String[]SplitSearchString(String search_string, char split_char, boolean clear_exact_match_char)
Splits the search string according to the following rule: 1.
ArrayList<String> result = new ArrayList();
String temps = "";
boolean delim_start = false;
for (int x = 0; x < search_string.length(); x++) {
    if (search_string.charAt(x) == EXACT_MATCH_CHAR) {
        delim_start = !delim_start;
        if (!clear_exact_match_char)
            temps += search_string.charAt(x);
...
String[]splitString(final String s, final char c, final boolean trimBlanks)
Optimized version of String#split that doesn't use regexps.
final char[] chars = s.toCharArray();
int num_substrings = 1;
final int last = chars.length - 1;
for (int i = 0; i <= last; i++) {
    char x = chars[i];
    if (x == c) {
        num_substrings++;
final String[] result = new String[num_substrings];
final int len = chars.length;
int start = 0; 
int pos = 0; 
int i = 0; 
for (; pos < len; pos++) {
    if (chars[pos] == c) {
        result[i++] = new String(chars, start, pos - start);
        start = pos + 1;
result[i] = new String(chars, start, pos - start);
if (trimBlanks) {
    int blanks = 0;
    final List<String> strs = new ArrayList<String>(result.length);
    for (int x = 0; x < result.length; x++) {
        if (result[x].trim().isEmpty()) {
            blanks++;
        } else {
            strs.add(result[x]);
    if (blanks == 0)
        return result;
    return strs.toArray(new String[result.length - blanks]);
return result;