Use myString.lastIndexOf(".") to get the index of the last dot.

For example, if you are sure that your input String contains at least one dot :

String name = myString.substring(0,myString.lastIndexOf("."));
Answer from Eran on Stack Overflow
๐ŸŒ
Alaab
alaab.net โ€บ ehc โ€บ java-split-string-by-dot-and-get-last-element
java split string by dot and get last element
STRING_SPLIT inputs a string that has delimited substrings, and inputs one character to use as the delimiter or separator. We can use the remove () method of ArrayList container in Java to remove the last element. Recommended Article. ", which is an edge case that produces an empty array when ...
Discussions

How to get the string before .(dot) and after /(last) slash in Java - Stack Overflow
I have a string like this: "core/pages/viewemployee.jsff" From this code, I need to get "viewemployee". How do I get this using Java? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Any simpler way to get the last element of a Java array? - Stack Overflow
Of course you could abstract the ...(sentence.split(" ")) or something. 2013-03-09T23:16:21.803Z+00:00 ... Sorry I didn't make my intention clear. I don't want to do this by declaring the array separately. 2013-03-09T23:17:13.287Z+00:00 ... If for some reason the sentence doesn't contain the token, it will throw an exception. 2013-12-06T18:15:27.007Z+00:00 ... String sentence = "Any simpler way to get the last element of a Java array?"; String ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
split - How to substring a string to the before last dot(.) in java? - Stack Overflow
I have a text file data.txt. I want to input the data into a Hashmap and do some datamapping. When ever I hit the value without dot(). I will get an error Exception in thread "main" java.lang. More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 24, 2016
java - How can I split a String in Expression Language and take the last element? - Stack Overflow
Read more here on Oacle The Java EE 5 Tutorial - JSTL Functions ยท Here is the code to get the last value based on split on dot. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Papergreen
ftp.papergreen.com.mx โ€บ tns โ€บ java-split-string-by-dot-and-get-last-element
java split string by dot and get last element
Split in Java uses a Regex. Python has reverse indexing, where -1 refer to the last element of a list, hope Java can implement it in the future release, then we can simplify the code like this: You're getting an ArrayIndexOutOfBoundsExceptionbecause your input string is just a dot, ie ".
๐ŸŒ
Codemia
codemia.io โ€บ home โ€บ knowledge hub โ€บ java get last element after split
Java Get last element after split | Codemia
July 31, 2025 - To access the last element of the resulting array, you can use: ... This way, lastWord would contain the value "efficiently". Java's String.split() uses regular expressions to identify delimiters. This means that sometimes a character needs to be escaped, especially if it has a special meaning in regex. For instance, splitting by a dot requires escaping:
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-split-string-by-dot
Java - Split String by Dot (.) - GeeksforGeeks
July 23, 2025 - After the loop ends, we print the last part of the string. We can use the StringTokenizer class for splitting strings by a dot. This method is considered outdated but still works well for splitting strings.
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2016 โ€บ 02 โ€บ 2-ways-to-split-string-with-dot-in-java-using-regular-expression.html
2 ways to Split String with Dot (.) in Java using Regular Expression? Examples
March 1, 2024 - If you want to split String on the dot you need to escape dot as \\. instead of just passing "." to the split() method. Alternatively, you can also use the regular expression [.] to split the String by a dot in Java.
๐ŸŒ
Pass4sure
pass4sure.com โ€บ blog โ€บ mastering-string-splitting-in-java-extracting-the-final-element-with-precision-and-performance
Mastering String Splitting in Java: Extracting the Final Element with Precision and Performance โ€“ IT Exams Training โ€“ Pass4Sure
One common task is dissecting a string based on a defined separator and then extracting particular pieces of that result. The operation of dividing a string into chunks using a delimiter is often accomplished using the split() method. Among the many possible follow-up tasks, a frequent requirement ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ split-string-with-dot-in-java
Split String with Dot (.) in Java
December 26, 2024 - The split() method of Java String is used to divide a string into an array of substrings. This method takes a string in the form of a regular expression as a parameter, searches the currently existing string with the given pattern, and splits ...
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ get the last word of a string
Get the Last Word of a String | Baeldung
August 7, 2025 - In this short tutorial, weโ€™ll learn how to get the last word of a String in Java using two approaches. The split() instance method from the String class splits the string based on the provided regular expression.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2022 โ€บ 09 โ€บ split-string-by-dot-in-java
Split String by Dot (.) in Java
September 28, 2022 - Here, we need to use double backslash before dot(.) to escape it else it would split the string using any character. ... public class JavaExample{ public static void main(String args[]){ //String that contains dot characters String str = "Text1.Text2.Text3.Text4"; //split the given string by ...
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 627606 โ€บ java โ€บ segments-dot-separated-string
get the last two segments from a dot separated string (Beginning Java forum at Coderanch)
January 26, 2014 - Also, split() takes a regex and a limit. Given the right regex, you'll only have two strings to deal with: the part that you want and the part that you can discard - the limit would be 1.
๐ŸŒ
Javadevnotes
javadevnotes.com โ€บ java-string-split-tutorial-and-examples
Java String Split Tutorial And Examples - JavaDevNotes
February 14, 2015 - The Java String's split method splits a String given the delimiter that separates each element.
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ java: get last element after split
Java: Get last element after split - Intellipaat
August 5, 2026 - The split() method in Java will give you an array of substrings. You can get the last element by accessing the last index. It works for well-formed input but throws ArrayIndexOutOfBoundsException if the input is empty. public class LastElementSplit ...