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
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A · ❮ String Methods · Split a string into an array of strings: String myStr = "Split a string by spaces, and also punctuation."; String regex = "[,\\.\\s]"; String[] myArray = myStr.split(regex); for (String s : myArray) { System.out.println(s); } Try it Yourself » ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › split-string-java-examples
Java String split() Method - GeeksforGeeks
May 13, 2026 - Explanation: In this example, a string "Geeks for Geeks" is created and split using the split(" ") method, where a space is used as the delimiter. This divides the string into individual words and stores them in an array arr.
🌐
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 - This confirms that the string was successfully split using the comma delimiter, each element was parsed into an integer, and all values were stored correctly in the array. Java Streams provide a more concise and expressive way to convert a string into an int array.
🌐
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.
🌐
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
🌐
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 - The split() method is a part of the String class in Java. It takes a regular expression as an argument, which determines where the splits will occur in the string. ... public class StringSplitter { public static void main(String[] args) { String ...
Find elsewhere
🌐
Attacomsian
attacomsian.com › blog › java-string-split
How to split a string in Java
July 4, 2021 - Java provides the String.split() method to split a string into an array based on the given regular expression.
🌐
Centron
centron.de › home › tutorials › how to convert string to array in java
How to Convert String to Array in Java – centron
February 7, 2025 - In this tutorial, we will explore the different methods to efficiently convert a String into an array in a Java program, providing clear examples and explanations to guide you step by step. ... Node applications need somewhere to run: ccloud³ VMs with full root access from €3.11 per month – or as a managed server if you would rather not run it yourself. Rent a cloud server → · The String class’s split(String regex) method can be used to convert a String to an array in Java.
🌐
YouTube
youtube.com › watch
Java - Split a string into an array | Arrays in Java - YouTube
If you have a string in Java, and you want to split it (explode it) into an array of smaller strings, how can you go about doing that? In this lecture we'll ...
Published: April 27, 2019
🌐
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).
🌐
Programiz
programiz.com › java-programming › library › string › split
Java String split() | Programiz
March 12, 2024 - 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.
🌐
Sentry
sentry.io › sentry answers › java › how to split a string in java
Java String Split: Use String.split() With Regex | Sentry
September 23, 2026 - 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.
🌐
freeCodeCamp
freecodecamp.org › news › string-to-array-in-java-how-to-convert-a-string-to-an-array-in-java
String to Array in Java – How to Convert Strings to Arrays
July 6, 2023 - Performance: Creating a new character ... especially for long strings. The split() method in Java is a convenient way to split a string into an array of substrings based on a specified delimiter....
🌐
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.
🌐
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 | LabEx
Java provides a built-in method called split() in the String class that allows us to divide a string into parts based on a delimiter. The method returns an array of strings containing the substrings divided by the delimiter.
🌐
Stack Abuse
stackabuse.com › how-to-split-a-string-in-java
How to Split a String in Java
September 20, 2023 - The substrings in the array include the trailing spaces in the original string, if there are any. When the limit is set to 0 - The String is again split as many times as possible, and there is no limit on the length of the resulting array. This works the same as calling the split() method, with ...
🌐
Scaler
scaler.com › home › topics › convert string to array in java
String to Array in Java - Scaler Topics
April 19, 2024 - The toArray() function of the List class can also be used to convert a string to array in Java. It accepts a list of type String as the input and converts each entity into an element of a string array.