Java Utililty Methods String Split

List of utility methods to do String Split

Description

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

Method

ArrayListsplit(final int limit, String text)
split
final ArrayList<String> splits = new ArrayList<String>();
if (text.length() > limit) {
    while (text.length() > limit) {
        final String sub = text.substring(0, limit);
        final int lastSpace = sub.lastIndexOf(" ");
        text = text.substring(lastSpace + 1);
        splits.add(sub);
    return splits;
splits.add(text);
return splits;
String[]split(final String s)
split
if (s == null) {
    return null;
final List<String> l = new ArrayList<String>();
for (final String i : s.split(",")) {
    if (i == null) {
        continue;
    final String sp = i.trim();
    if (sp.length() == 0) {
        continue;
    l.add(sp);
return l.toArray(new String[0]);
Iterablesplit(final String s)
split
return new Iterable<String>() {
    public Iterator<String> iterator() {
        return new Iterator<String>() {
            private int from = 0;
            public boolean hasNext() {
                return from <= s.length();
            public String next() {
...
Listsplit(final String s)
This is not correct.
final List<String> res = new ArrayList<>();
int len1 = s.length();
String s1 = s;
while (true) {
    final String s2 = s1.replace("  ", " ");
    final int len2 = s2.length();
    s1 = s2;
    if (len2 == len1) {
...
Listsplit(final String str)
split
if (str.contains(",")) {
    @SuppressWarnings("unchecked")
    final List<String> splitValues = Arrays.asList(str.split(","));
    return splitValues;
} else {
    final List<String> values = new ArrayList<String>(1);
    values.add(str);
    return values;
...
String[]split(final String str)
Split a given string.
return split(str, ESCAPE, COMMA);
Listsplit(final String string)
Dada una cadena escrita en camelCase retorna una lista con los elementos que forman la cadena

Por ejemplo

  1. HolaMundo, retorna [Hola,Mundo]

List<String> list = new ArrayList<String>();
int j = 0;
for (int i = 1; i < string.length(); i++) {
    if (MAYUSCULAS.contains(string.charAt(i))) {
        list.add(string.substring(j, i));
        j = i;
list.add(string.substring(j, string.length()));
return list;
String[]split(final String string)
split
return split(string, null);
Listsplit(final String string, final String toSplit)
Splits the passed string based on the toSplit string.
if (toSplit.length() == 1) {
    return split(string, toSplit.charAt(0));
ArrayList<String> ret = new ArrayList<String>();
if (toSplit.length() == 0) {
    ret.add(string);
    return ret;
int len = string.length();
int last = 0;
char c = 0;
for (int i = 0; i < len; i++) {
    c = string.charAt(i);
    if (c == toSplit.charAt(0) && matches(string, toSplit, i)) {
        if (last != i) {
            ret.add(string.substring(last, i));
        last = i + toSplit.length();
        i += toSplit.length() - 1;
if (last < len) {
    ret.add(string.substring(last, len));
return ret;
String[]split(final String text, final String sp)
Genera una lista de cadenas compuesta por los fragmentos de texto separados por la cadena de separación indicada.
final ArrayList<String> parts = new ArrayList<String>();
int i = 0;
int j = 0;
while (i != text.length() && (j = text.indexOf(sp, i)) != -1) {
    if (i == j) {
        parts.add(""); 
    } else {
        parts.add(text.substring(i, j));
...