This behavior is explicitly documented in String.split(String regex) (emphasis mine):

This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.

If you want those trailing empty strings included, you need to use String.split(String regex, int limit) with a negative value for the second parameter (limit):

String[] array = values.split("\\|", -1);
Answer from Mark Rotteveel on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_string_split.asp
Java String split() Method
The split() method splits a string into an array of substrings using a regular expression as the separator. If a limit is specified, the returned array will not be longer than the limit.
Discussions

java - Split String into an array of String - Stack Overflow
I'm trying to find a way to split a String into an array of String(s), and I need to split it whenever a white spice is encountered, example "hi i'm paul" into" "hi" "i'm" "paul" How do you More on stackoverflow.com
🌐 stackoverflow.com
Using charAt(index) method to split a String into an array.
You've got the right idea to use String.charAt(). That gives you a char. Is there any method in the Character class that could tell you if what you have is not a delimiter character? Once you have that you'll need some way to store these words. If the assignment specifies an array then you'll need to declare an array large enough to hold the words or dynamically resize the array as needed. One is certainly easier than the other. If you don't have to use an array then you might want to use some other sort of data structure. Have you learned about lists yet? More on reddit.com
🌐 r/javahelp
9
2
November 22, 2016
split comma separated list, and strip spaces.

howdy stib,

the simplest solution is to use .Trim() on the results of your split. that will trim away any leading/trailing spaces. [grin] something like this ...

'foo, foo bar, fuzz, baz'.Split(',').Trim()   

take care,
lee

More on reddit.com
🌐 r/PowerShell
17
6
August 19, 2019
Split a string with multiple delimiters

Erm, you can just put all of the delimiters you want in the quotes for the string passed to .split()

[PS] C:\Users\> $string = "part1.part2;part3"
[PS] C:\Users\> $string.split(".;")
part1
part2
part3
More on reddit.com
🌐 r/PowerShell
7
19
October 14, 2014
🌐
GeeksforGeeks
geeksforgeeks.org › java › split-string-java-examples
Java String split() Method - GeeksforGeeks
May 13, 2026 - The split() method in Java is used to divide a string into multiple parts based on a specified delimiter (regular expression). It returns an array of substrings after splitting the original string.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
How to Split a String into an Int Array in Java - Java Code Geeks
November 10, 2025 - In this example, the regular expression [,; ]+ tells Java to split the string wherever a comma, semicolon, or space appears. Each substring is then converted into an integer, giving you a clean array of numbers even when the input isn’t uniformly formatted.
🌐
Delft Stack
delftstack.com › home › howto › java › how to split string to array in java
How to Split String to Array in Java | Delft Stack
March 11, 2025 - Whether you are a beginner or looking ... straightforward ways to split a string into an array in Java is by using the built-in split() method from the String class....
🌐
Codebind
codebind.com › home › java example – split string into array in java
Java Example – Split String Into Array in Java
September 12, 2017 - */ System.out.println(""); ... i++) System.out.println(tempArray[i]); /* Using second argument in the String.split() method, we can control the maximum number of substrings generated by splitting a strin...
🌐
Codecademy
codecademy.com › docs › java › strings › .split()
Java | Strings | .split() | Codecademy
March 30, 2022 - The .split() method takes a string and splits it into an array of substrings based on a pattern delimiter. The pattern provided is a regular expression that will split the original string based on where the pattern is matched in the string.
Find elsewhere
🌐
YouTube
youtube.com › oggi ai - artificial intelligence today
Java: Split String at Delimiter | break String into Array of Substrings - YouTube
This video explains how to split a string in Java into an array of substrings, at one or more delimiter characters such as space, period, or comma. Code: htt...
Published: April 20, 2023
Views: 1K
🌐
Guru99
guru99.com › home › java tutorials › split() string method in java: how to split string with example
Split() String Method in Java: How to Split String with Example
December 26, 2023 - In this Java split string by delimiter case, the separator is a comma (,) and the result of the Java split string by comma operation will give you an array split.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › how to split string into array [practical examples]
How to split String into Array [Practical Examples] | GoLinuxCloud
February 22, 2022 - In this case, we will need to split the string into its equivalent words. Java provides the split() function in a string class that helps in splitting the string into an array of string values.
🌐
Codefinity
codefinity.com › courses › v2 › 0bfa1111-8677-478f-bcd3-315dff1d7d40 › 421ab035-77e8-4fef-abb9-488c91c2d1f9 › 433c4bac-9f33-4b48-9be0-cdc81423c941
Learn Method split() | String Advanced
The split(String delimiter) method splits a string into an array of substrings based on the specified delimiter (a character or sequence of characters). It returns an array where each element is a substring from the original string, separated ...
🌐
Attacomsian
attacomsian.com › blog › java-convert-string-to-array
How to convert a string to an array in Java
October 29, 2022 - The most common way to split a string into an array in Java is the String.split() method.
🌐
Briebug
blog.briebug.com › home › articles › using the java string.split() method
Using the Java String.split() Method | Briebug
October 13, 2022 - The Java String.split() method has two variations, commonly known as method overloading, which are both used to split a String into an array of Strings, using a passed delimiter or regular expression.
🌐
Centron
centron.de › startseite › how to convert string to array in java
Convert String to Array in Java: A Complete Guide
February 7, 2025 - The above program splits the String into an array of words using two different methods: the split method of the String class and the split method of the Pattern class. Java also offers a legacy class called StringTokenizer, but it is outdated and not recommended.
🌐
Programiz
programiz.com › java-programming › library › string › split
Java String split()
The Java String split() method divides the string at the specified separator and returns an array of substrings. In this tutorial, you will learn about the Java split() method with the help of examples.
🌐
Baeldung
baeldung.com › home › java › java string › java string.split()
Java.String.split() | Baeldung
July 15, 2026 - The split() method handles cases with leading delimiters by creating empty strings (“”) in the resulting array. However, trailing delimiters are ignored unless we explicitly specify a limit of -1. When the limit is set to -1, the split() method includes empty strings caused by trailing delimiters in the resulting array:
🌐
Sentry
sentry.io › sentry answers › java › how to split a string in java
How to split a string in Java | Sentry
public class Main { public static void main(String[] arg) { String str = "how.to.split.a.string.in.java"; String[] arrOfStr = str.split("\\."); for (String a : arrOfStr) { System.out.println(a); } } } This example also has the same output as the previous examples. If the split character is not present in the target string, the output will be an array with one element containing the entire string.
🌐
How to do in Java
howtodoinjava.com › home › string › java string split() : splitting by one or multiple delimiters
Java String split() : Splitting by One or Multiple Delimiters
October 12, 2023 - It returns an array of split strings after the method splits the given string around matches. For using the multiple delimiters, the regular expression should define a character class that includes all the delimiters we want to split by. The regular expression must be a valid pattern and we must remember to escape special characters if necessary. String str = "how-to-do.in.java"; String[] strArray1 = str.split("-"); //[how, to, do.in.java] - 3 tokens String[] strArray2 = str.split("-|\\."); //[how, to, do, in, java] - 5 tokens
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › split
Java String split() - Split String | Vultr Docs
December 17, 2024 - The split() method in Java is immensely beneficial for breaking up strings into arrays based on specified delimiters. It facilitates data manipulation, especially in scenarios involving structured text files like CSVs.