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 String to Array split
Array[r++] = row.split("\\|"); that won't even compile, as "Array" (horrible variable name btw) isn't defined. Did you try googling this? there's a zillion tutorials about how to split strings... also: r/javahelp . More on reddit.com
๐ŸŒ r/java
1
0
January 1, 2014
Java- Converting a string of numbers separated by spaces into an array?
You have the right idea. String.split() will return an array of strings. Then, if you want to treat any individual string in that array as an integer you can use Integer.parseInt() . If you want to create an array of integers, just make the array that way. More on reddit.com
๐ŸŒ r/learnprogramming
7
4
February 2, 2016
How do I turn a string into a string array with each word being a different part of the array?
Use the split string function. The following will split at spaces. The thing in parenthesis are called the regular expressions. Just look at the Java API to figure out how to parse the punctuation. String str = "foo bar"; String strArr[]; strArr = str.split("\\s+"); You probably have to write code to look through each member of the string first to change all characters to lowercase. So, write a toLower() function or something. Alternatively, look at the the String class in the Java API. You might just find that there may or may not be a toLowerCase() method already there. Here's are the links to the Java API: String class: http://docs.oracle.com/javase/7/docs/api/java/lang/String.html Regex (regular expressions): http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#sum (The Java API is your friend. Use it if you need to figure out how to do stuff. It's probably already there for you.) More on reddit.com
๐ŸŒ r/javahelp
6
1
December 2, 2014
Java Splitting a string into a 2d array
Why don't you just access the 1D array like a 2D array? index = x*width+y More on reddit.com
๐ŸŒ r/programminghelp
5
2
September 19, 2012
๐ŸŒ
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...
๐ŸŒ
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 ...
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
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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...
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ string-to-array-java
How to Convert String to Array in Java | DigitalOcean
August 3, 2022 - Technical tutorials, Q&A, events โ€” This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.