String.split() has some very surprising semantics, and it's rarely what you want. You should prefer StringUtils (or Guava's Splitter, discussed in the previous link).

Your specific issue is that String.split() takes a regular expression, while StringUtils.split() uses each character as a separate token. You should use StringUtils.splitByWholeSeparator() to split on the contents of the full string.

StringUtils.splitByWholeSeparator(str, "__|__");
Answer from dimo414 on Stack Overflow
🌐
Apache Commons
commons.apache.org › proper › commons-lang › apidocs › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.20.0 API)
Split/Join - splits a String into an array of substrings and vice versa ... The StringUtils class defines certain words related to String handling.
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-2.6 › org › apache › commons › lang › StringUtils.html
StringUtils (Commons Lang 2.6 API)
For more control over the split use the StrTokenizer class. A null input String returns null. StringUtils.split(null) = null StringUtils.split("") = [] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split(" abc ") = ["abc"]
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.3 › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.3 API)
For more control over the split use the StrTokenizer class. A null input String returns null. StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("a.b.c", '.') = ["a", "b", "c"] StringUtils.split("a..b.c", '.') = ["a", "b", "c"] StringUtils.split("a:b:c", '.') = ["a:b:c"] StringUtils.split("a b c", ' ') = ["a", "b", "c"]
🌐
Eduardo Figueiredo
homepages.dcc.ufmg.br › ~andrehora › examples › org.apache.commons.lang3.StringUtils.split.11.html
org.apache.commons.lang3.StringUtils.split
public class SplitString { public static void main(String[] args) { //Split a String into an Array using # as seperator. String [] splitArr=StringUtils.split("AB#CD#EF#GH", "#"); for(int i=0; i<splitArr.length; i++ ) { System.out.println( i + ") "+ splitArr[i]); } } }
🌐
Tabnine
tabnine.com › home page › code › java › org.apache.commons.lang.stringutils
org.apache.commons.lang.StringUtils.split java code examples | Tabnine
For more control over the split use the StrTokenizer class. A null input String returns null. StringUtils.split(null) = null StringUtils.split("") = [] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split(" abc ") = ["abc"]
🌐
Baeldung
baeldung.com › home › java › java string › split a string in java
Split a String in Java | Baeldung
January 8, 2024 - String[] splitted = "peter,james,thomas".split(","); ... Apache’s common lang package provides a StringUtils class – which contains a null-safe split() method, that splits using whitespace as the default delimiter:
🌐
Tabnine
tabnine.com › home page › code › java › org.apache.commons.lang3.stringutils
org.apache.commons.lang3.StringUtils.split java code examples | Tabnine
For more control over the split use the StrTokenizer class. A null input String returns null. StringUtils.split(null) = null StringUtils.split("") = [] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split(" abc ") = ["abc"]
Find elsewhere
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-2.5 › org › apache › commons › lang › StringUtils.html
StringUtils (Commons Lang 2.5 API) - Apache Commons
For more control over the split use the StrTokenizer class. A null input String returns null. StringUtils.split(null) = null StringUtils.split("") = [] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split("abc def") = ["abc", "def"] StringUtils.split(" abc ") = ["abc"]
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.1 › org › apache › commons › lang3 › StringUtils.html
StringUtils (Commons Lang 3.1 API)
For more control over the split use the StrTokenizer class. A null input String returns null. StringUtils.split(null, *) = null StringUtils.split("", *) = [] StringUtils.split("a.b.c", '.') = ["a", "b", "c"] StringUtils.split("a..b.c", '.') = ["a", "b", "c"] StringUtils.split("a:b:c", '.') = ["a:b:c"] StringUtils.split("a b c", ' ') = ["a", "b", "c"]
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-release › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.11 API)
Split/Join - splits a String into an array of substrings and vice versa ... The StringUtils class defines certain words related to String handling.
🌐
GitHub
github.com › apache › commons-lang › blob › master › src › main › java › org › apache › commons › lang3 › StringUtils.java
commons-lang/src/main/java/org/apache/commons/lang3/StringUtils.java at master · apache/commons-lang
* A {@code null} input String returns {@code null}. A {@code null} separator splits on whitespace. ... * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "de", "fg"]
Author   apache
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-handling-with-apache-commons-stringutils-class-in-java
String Handling with Apache Commons' StringUtils Class in Java - GeeksforGeeks
April 28, 2025 - If you want to split on a different character or sequence of characters, you'll need to pass that in as a parameter to the split() method. Overall, the StringUtils class is a powerful and convenient tool for working with Strings in Java.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › apache-stringutils
Newest 'apache-stringutils' Questions - Stack Overflow
I am using Jaspersoft Studio 6.21.2. My project has a report that has a field with this value expression: StringUtils.defaultIfBlank($P{SEARCH_CRITERIA_STRING}, "") The method ... ... I have sample strings like below, abc/def/ghi/test/yvw/syz abc/fed/igh/test_123/wuvacv/zyxh I want to get it like below abc/def/ghi/test abc/fed/igh/test_123 So what are the best way to follow for ... ... Java 11 here. I am trying to use org.apache.commons.lang3.StringUtils.join to take a list of strings and join/concatenate them into a single string, separated by an @ sign.