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);
Related Posts:
- How to split a string in Java
- How to split a String by space
- How to split a string in Java
- What does regular expression \\s*,\\s* do?
- Java split string to array
- How do I convert a String to an int in Java?
- How to format strings in Java
- How do I compare strings in Java?
- How to convert a char to a String?
- Reverse a string in Java
- Reverse a string in Java
- Java String Split by “|”
- Convert String to double in Java
- Java String new line
- How to check if a String contains another String in a case insensitive manner in Java?
- String concatenation: concat() vs “+” operator
- How to remove the last character from a string?
- Java string to date conversion
- How to replace � in a string
- Change date format in a Java string
- What are all the escape characters?
- Converting String to “Character” array in Java
- string to string array conversion in java
- Best way to convert an ArrayList to a string
- Best way to convert an ArrayList to a string
- String interpolation in Java 14 or 15
- Understanding regex in Java: split(“\t”) vs split(“\\t”) – when do they both work, and when should they be used
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- How to remove single character from a String
- How to parse this string in Java?
- How to convert any Object to String?
- Illegal Escape Character “\”
- Can I multiply strings in Java to repeat sequences?
- How to convert a Binary String to a base 10 integer in Java
- Left Hand Side of an Assignment must be a Variable CharAt
- How to capitalize the first letter of a String in Java?
- catDog string problem at Codingbat.com
- Java way to check if a string is palindrome
- Return string Input with parse.string
- What is the difference between String.subString() and String.subSequence()
- How do I apply the for-each loop to every character in a String?
- Java – removing first character of a string
- Explain the use of a bit vector for determining if all characters are unique
- Explain the use of a bit vector for determining if all characters are unique
- Sort a single String in Java
- How to remove single character from a String
- How to remove single character from a String
- What is Java String interning?
- What is Java String interning?
- What is Java String interning?
- Why is there no String.Empty in Java?
- Using Enum values as String literals
- What is the easiest/best/most correct way to iterate through the characters of a string in Java?
- int cannot be converted to string?
- How to check if my string is equal to null?
- what is Ljava.lang.String;@
- Convert String to int array in java
- How to sort an array of objects in Java?
- How to sort an array of objects in Java?
- How to compress a String in Java?
- java.lang.NumberFormatException: empty String
- How to check if a String is numeric in Java
- Converting A String To Hexadecimal In Java
- Converting a string to an integer on Android
- Simple way to repeat a string
- Java end of file
- Unclosed Character Literal error
- Java: how to initialize String[]?
- Regular Expressions on Punctuation
- Add String Array to ArrayList
- StringIndexOutOfBoundsException String index out of range: 0
- difference between equals() and hashCode()
- How can I check if a single character appears in a string?
- Difference between String replace() and replaceAll()
- Java String to SHA1
- Replace a character at a specific index in a string?
- Determine if a String is an Integer in Java [duplicate]
- How to convert a String to CharSequence?
- How do I convert a String to a BigInteger?
- How can I remove a substring from a given String?
- Java get String CompareTo as a comparator object
- Get an OutputStream into a String
- Difference between string object and string literal
- How to convert a String into an ArrayList?
- java: use StringBuilder to insert at the beginning
- How do I get the last character of a string?
- Cannot invoke toString() on the primitive type int
- How to compare character ignoring case in primitive types
- Append a single character to a string or char array in java?
- convert string to arraylist
in java - How to insert multiple tabs string in java?
- Append a single character to a string or char array in java?
- Why cannot cast Integer to String in java?
- Split string into array of character strings
- Removing double quotes from a string in Java
- Occurrences of substring in a string
- Append a single character to a string or char array in java?
- Quotation marks inside a string
- In Java, how do I parse XML as a String instead of a file?
- Fastest way to put contents of Set
to a single String with words separated by a whitespace?