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
๐ŸŒ
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 consecutive delimiters String str = "Text1,##::Text2"; //Specified the delimiters inside brackets String[] strArray = str.split("[,#:]"); for(String s: strArray){ System.out.println(s); } } }
๐ŸŒ
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 - 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 ...
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ split in java
Java String split() Method Explained with Examples and Use Cases
May 30, 2025 - 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.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2022 โ€บ 09 โ€บ how-to-split-a-string-in-java-with-delimiter
How to Split a String in Java with Delimiter
September 21, 2022 - You can break the the string using //any delimiter such as dot, backslash, pipe, tab etc String[] strArray = str.split(","); for(String s: strArray){ System.out.println(s); } } } ... Example 2: Passing a regular expression to break the input string using multiple delimiters. public class ...
๐ŸŒ
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.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ java string.split()
Java.String.split() | Baeldung
November 9, 2017 - 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, ...
๐ŸŒ
Interview Kickstart
interviewkickstart.com โ€บ home โ€บ blogs โ€บ learn โ€บ java string split() method: syntax, delimiters, and examples
Java String split() Method: Syntax, Delimiters, and Examples
April 1, 2026 - Yes, you can split by multiple delimiters in a single call by using a regex character set. For example, using split(โ€œ[,;|]โ€) will instruct Java to break the string whenever it encounters a comma, a semicolon, or a pipe character.
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2014 โ€บ 02 โ€บ stringtokenizer-example-in-java-multiple-delimiters.html
StringTokenizer Example in Java with Multiple Delimiters - Example Tutorial
Always Prefer String's split() method for splitting String and for repeated split use Pattern.split() method. Coming back to StringTokenizer, we will see three examples of StringTokenizer in this article. The first example is to break String based on white-space, the second example will show how to use multiple delimiters, and the third example will show you how to count the number of tokens.
๐ŸŒ
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.
๐ŸŒ
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).