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 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
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
🌐
GeeksforGeeks
geeksforgeeks.org › java › split-string-java-examples
Java String split() Method - GeeksforGeeks
May 13, 2026 - This divides the string into individual words and stores them in an array arr. A for-each loop then iterates over the array and prints each word on a new line. This code depicts how a string can be split using spaces, commas, and dots together.
🌐
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.
🌐
Codecademy
codecademy.com › docs › java › strings › .split()
Java | Strings | .split() | Codecademy
March 30, 2022 - Splits a string into an array of substrings based on a delimiter pattern.
🌐
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.
🌐
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...
Find elsewhere
🌐
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....
🌐
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
🌐
DigitalOcean
digitalocean.com › community › tutorials › string-to-array-java
How to Convert String to Array in Java | DigitalOcean
August 4, 2022 - package com.journaldev.util; import java.util.Arrays; import java.util.regex.Pattern; public class StringToArrayExample { /** * This class shows how to convert String to String Array in Java * @param args */ public static void main(String[] args) { String line = "My name is Pankaj"; //using String split function String[] words = line.split(" "); System.out.println(Arrays.toString(words)); //using java.util.regex Pattern Pattern pattern = Pattern.compile(" "); words = pattern.split(line); System.out.println(Arrays.toString(words)); } }
🌐
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.
🌐
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
You may also notice that the method removes the specified character from the resulting array when splitting. To split a string into an array at each occurrence of a single character, we can simply use empty quotation marks "" as the parameter.
🌐
Baeldung
baeldung.com › home › java › java string › java string.split()
Java.String.split() | Baeldung
4 days ago - Each element in the array is a substring from the original string. The regex is the regular expression that defines the delimiter. We can also pass a limit on the number of splits to the split() method.
🌐
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.
🌐
Tech Nexus
tdev.umb.edu › view › post › how-to-split-string-into-string-array-in-java
how to split string into string array in java
September 6, 2024 - public class MultiDelimiterSplitter { public static void main(String[] args) { String data = "One;Two,Three.Four:Five"; // Splitting the string with multiple delimiters String[] dataArray = data.split("[;,.:]"); // Printing 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.
🌐
Medium
medium.com › @AlexanderObregon › javas-string-split-method-explained-77bdaddaae79
Java’s String split() Method Explained
June 25, 2024 - The split() method allows you to divide a string into an array of substrings based on a specified delimiter, which can be useful in various scenarios such as parsing data, manipulating text, and more.
🌐
LabEx
labex.io › tutorials › java-how-to-split-a-string-into-an-arraylist-using-a-delimiter-in-java-415655
How to split a string into an ArrayList using a delimiter in Java
Learn technical skills with AI and interactive hands-on labs. The AI assistant powered by ChatGPT can help you get unstuck and level up skills quickly while practicing in the in-browser environment.
🌐
Programiz
programiz.com › java-programming › library › string › split
Java String split()
The split() method divides the string at the specified regex and returns an array of substrings. class Main { public static void main(String[] args) { String text = "Java is a fun programming language";