This is probably the easiest way (also note that depending on the context this is not necessarily correct, for example, ".tar.gz").
You can also split character based string . , and take the last piece, but it's just as difficult.
Is there any special reason why you are trying to avoid substring and lastIndexOf ?
source share