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
java - Split string into array of character strings - Stack Overflow
I need to split a String into an array of single character Strings. Eg, splitting "cat" would give the array "c", "a", "t" ... As a quick reference, "".join(["c","a","t"]) to get "cat" back. ... Java 8: .split("") will do it. 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
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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)); } }
๐ŸŒ
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 ...
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ convert string to array in java
String to Array in Java - Scaler Topics
April 19, 2024 - Example 2: We changed the string to array in Java in the following example using the # delimiter. ... The Pattern.split() method uses a regular expression(pattern) as the delimiter to split a string into an array of strings.
๐ŸŒ
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
๐ŸŒ
Quora
quora.com โ€บ How-do-you-split-a-string-and-store-it-in-an-array-in-Java
How to split a string and store it in an array in Java - Quora
Answer (1 of 3): SPLIT Meaning:- To divide or to make a group of people/things divide into smaller groups. In java. lang. String. split(String regex, int limit) method splits this string around matches of the given regular expression. The array returned by this method contains each substring of...
๐ŸŒ
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
๐ŸŒ
Centron
centron.de โ€บ startseite โ€บ how to convert string to array in java
Convert String to Array in Java: A Complete Guide
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. The String classโ€™s split(String regex) method can be used to convert a String to an array in Java.