-2

Split method not working with "." in android and java .

String[] extension = selectedItem.getmName().split(".");

3 Answers3

0

Try :

String[] extension = FilenameUtils.getExtension(selectedItem.getName())

Reference : How do I get the file extension of a file in Java?

Illya
  • 1,268
  • 1
  • 5
  • 16
0

Simply escape the ".":

String[] sentences = selectedItem.getmName().split("\\.");

Since "." is regex for any character the result would always be an array of 0 length since every character is a delimeter and split only returns what is not a delimeter - which would be nothing.

0
String[] sentences = selectedItem.getmName().split("\\.");

This must works. This is a special situation for dot.