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[]split(String s, char c)
Splits a character-delimited string into a string array.
char[] unEscapeChars = new char[] { '\\', c };
if (s == null)
    return null;
if (isEmpty(s))
    return new String[0];
if (s.indexOf(c) == -1)
    return new String[] { s };
List<String> l = new LinkedList<String>();
...
Listsplit(String s, char c)
split
List<String> ret = new ArrayList<>();
int prev = 0;
while (true) {
    int pos = s.indexOf('\n', prev);
    if (pos == -1) {
        break;
    ret.add(s.substring(prev, pos));
...
String[]split(String s, char c, int limit)
split
if (s == null)
    return null;
ArrayList<Integer> pos = new ArrayList<Integer>();
int i = -1;
while ((i = s.indexOf((int) c, i + 1)) > 0) {
    pos.add(Integer.valueOf(i));
int n = pos.size();
...
String[]split(String s, char c, int limit)
split
if (s == null) {
    return null;
ArrayList<Integer> pos = new ArrayList<Integer>();
int i = -1;
while ((i = s.indexOf((int) c, i + 1)) > 0) {
    pos.add(i);
int n = pos.size();
int[] p = new int[n];
i = -1;
for (int x : pos) {
    p[++i] = x;
if ((limit == 0) || (limit > n)) {
    limit = n + 1;
String[] result = new String[limit];
if (n > 0) {
    result[0] = s.substring(0, p[0]);
} else {
    result[0] = s;
for (i = 1; i < limit - 1; ++i) {
    result[i] = s.substring(p[i - 1] + 1, p[i]);
if (limit > 1) {
    result[limit - 1] = s.substring(p[limit - 2] + 1);
return result;
String[]split(String s, char ch)
split
if (isEmpty(s)) {
    return EMPTY_STRING_ARRAY;
int lastPos = 0;
int curPos = s.indexOf(ch);
if (curPos < 0) {
    return new String[] { s };
Collection<String> values = new LinkedList<>();
do {
    String v = s.substring(lastPos, curPos);
    values.add(v);
    lastPos = curPos + 1;
    if (lastPos >= s.length()) {
        break;
    curPos = s.indexOf(ch, lastPos);
    if (curPos < lastPos) {
        break; 
} while (curPos < s.length());
if (lastPos < s.length()) {
    String v = s.substring(lastPos);
    values.add(v);
return values.toArray(new String[values.size()]);
ArrayListsplit(String s, char divider)
Split a string into pieces based on the given divider character.
ArrayList retList = new ArrayList();
int last = 0;
int sLength = s.length();
int i = 0;
for (; i < sLength; ++i) {
    if (s.charAt(i) == divider) {
        retList.add(s.substring(last, i));
        last = i + 1;
...
voidsplit(String s, char divider, String[] output)
Split a string into pieces based on the given divider character
int last = 0;
int current = 0;
int i;
for (i = 0; i < s.length(); ++i) {
    if (s.charAt(i) == divider) {
        output[current++] = s.substring(last, i);
        last = i + 1;
output[current++] = s.substring(last, i);
while (current < output.length) {
    output[current++] = "";
Listsplit(String s, char sep)
Splits a string around instances of the given character separator.
return Arrays.asList(s.split("\\Q" + sep + "\\E"));
String[]split(String s, char sep)
Convert a string of items separated by a separator character to an array of the items.
ArrayList al = new ArrayList();
int start_pos, end_pos;
start_pos = 0;
while (start_pos < s.length()) {
    end_pos = s.indexOf(sep, start_pos);
    if (end_pos == -1) {
        end_pos = s.length();
    String found_item = s.substring(start_pos, end_pos);
    al.add(found_item);
    start_pos = end_pos + 1;
if (s.length() > 0 && s.charAt(s.length() - 1) == sep) {
    al.add(""); 
String[] returned_array = new String[al.size()];
al.toArray(returned_array);
return returned_array;
String[]split(String splittee, String splitChar)
split
return split(splittee, splitChar, 0);