I think you need to include the regex OR operator:

String[]tokens = pdfName.split("-|\\.");

What you have will match:
[DASH followed by DOT together] -.
not
[DASH or DOT any of them] - or .

Answer from Richard H on Stack Overflow
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ splitting a java string by multiple delimiters
Splitting a Java String by Multiple Delimiters | Baeldung
August 7, 2025 - We just have to define an input string we want to split and a pattern. The next step is to apply a pattern. A pattern can match zero or multiple times. To split by different delimiters, we should just set all the characters in the pattern.
People also ask

Can split() handle leading or trailing delimiters?
Yes, it can. If a delimiter appears at the start or end of the string, the method includes empty strings in the resulting array. To remove them, you can post-process the array or adjust the limit parameter accordingly.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ split in java
Java String split() Method Explained with Examples and Use Cases
How does split() behave when used on an empty string?
When used on an empty string with any delimiter, split() returns an array with one empty string element ([""]). If the delimiter matches, it can return an array of multiple empty strings, depending on the pattern and limit.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ split in java
Java String split() Method Explained with Examples and Use Cases
What happens if the delimiter is not found in the string?
If the delimiter or regex is not present in the string, the split() method returns an array containing the original string as the only element. It means no splitting occurred due to the absence of the pattern.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ split in java
Java String split() Method Explained with Examples and Use Cases
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ string โ€บ java string split(): limit, regex escaping and empty strings
Java String split() : Splitting by One or Multiple Delimiters
October 12, 2023 - A character class such as [,;] splits on any one of the listed characters, and adding + treats a run of delimiters as one. An alternation with | handles delimiters that are longer than one character, and \\s* around a delimiter removes the spaces ...
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2022 โ€บ 09 โ€บ split-string-by-multiple-delimiters-in-java
Split String by Multiple Delimiters in Java
September 30, 2022 - public class JavaExample { public static void main (String[] args) { //A string with multiple delimiters String str = "Text1,Text2#Text3 Text4:Text5.Text6"; //Specified the delimiters inside brackets, there is a //whitespace after # to consider space as delimiter as well String[] strArray = str.split("[,# :.]"); for(String s: strArray){ System.out.println(s); } } }
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 443303 โ€บ java โ€บ splitting-string-multiple-delimiters
splitting a string with multiple delimiters (Java in General forum at Coderanch)
for example i have these delimiters in string array---->String[] sep_list = { " ", "\n","[","]","{","}","(",")"}; how can we split it in one go... ... String.split takes a regular expression. Take a look at the API of java.util.regex.Pattern to see what this pattern can look like. You can read there how to get a "choice" pattern. SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6 How To Ask Questions How To Answer Questions ... First I would replace String[] sep_list = { " ", "\n","[","]","{","}","(",")"}; with Character[] sep_list = { ' ', '\n', '[', ']', '{', '}', '(', ')' }; or not Then look at java.util.regex.Pattern class, it has static method called quote(String) and it returns "A literal string replacement" Now you call it like Pattern.quote(sep_list[someIndex].toString()) and add it to your pattern.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ split a string in java and keep the delimiters
Split a String in Java and Keep the Delimiters | Baeldung
June 24, 2025 - String[] splits = StringUtils.splitByCharacterType("pg@no;10@hello;world@this;is@a#10words;Java#Program"); The different character types as seen in the above string are uppercase and lowercase letters, digits, and special characters (@ ; # ). Hence, the resulting array splits, as expected, looks like: [pg, @, no, ;, 10, @, hello, ;, world, @, this, ;, is, @, a, #, 10, words, ;, J, ava, #, P, rogram] In this article, weโ€™ve seen how to split a string in such a way that the delimiters are also available in the resulting array.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ split in java
Java String split() Method Explained with Examples and Use Cases
May 30, 2025 - You must escape them using double backslashes (\\. or \\|) to split the string correctly without regex conflicts or unexpected behavior. To split using multiple delimiters, you can use a regex pattern with the OR operator (|).
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ fixitkalia
Java :Use String.split() with multiple delimiters(5solution) - YouTube
Thanks for watching this videoPlease Like share & Subscribe to my channel
Published: December 1, 2022
Views: 240
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ split-a-string-in-java-with-delimiter
How to Split a String in Java with Delimiter? - GeeksforGeeks
July 23, 2025 - In Java, the split() method of the String class is used 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 - In this article, we explored the String.split() method, which allows us to divide strings into smaller substrings based on specified delimiters. We learned how to use this method with regular expressions, handle different character encodings, ...
๐ŸŒ
CodingTechRoom
codingtechroom.com โ€บ tutorial โ€บ java-java-string-split-multiple-delimiters
Java String Split with Multiple Delimiters: An Expert Guide - CodingTechRoom
The simplest way to split a string by multiple delimiters is to use the `String.split()` method along with regular expressions.
๐ŸŒ
Javaprogramto
javaprogramto.com โ€บ 2020 โ€บ 07 โ€บ java-string-split-examples-on-how-to-split-a-string.html
Java String split() Examples on How To Split a String With Different Delimiters
December 6, 2020 - If the string is ending with delimiters and all of these are discarded when split(regex) method is executed. But if you want to get those values also then need to pass the limit value.
๐ŸŒ
Iditect
iditect.com โ€บ faq โ€บ java โ€บ use-stringsplit-with-multiple-delimiters-in-java.html
Use String.split() with multiple delimiters in java
We use the split("[,;\\s]+") method to split the string using multiple delimiters: , (comma), ; (semicolon), and \\s (space).