String.split() accepts a regular expression, so if you want to split by special character you need to escape . for it not to be considered as a regex meta character. For example, if you have the filename as:

SomeFile.jpg, to get its extension you’ll need to:

String[] fileNameParts = filename.split("\\.");

return fileNameParts[fileNameParts.length -1];

Newsletter

Please enable the javascript to submit this form