I'm working on my programming assignment, and trying to understand an issue occuring with String#split() method in Java. I've tried for 3 hours and then asking- How to split a string in Java. Here is the code snippet of it-
The Program
class FileProcessor
{
public static void fileNameProcessor(String fileName)
{
System.out.println("\n\n---- PROCESSING FILE NAMES -----\n\n");
fileName = "SampleName.java"; // Let's assume the method receives this string
String fileNameParts[] = fileName.split(".");
for (int i = 0; i < fileNameParts.length; i++)
System.out.println("File Information : " + fileNameParts[i]);
System.out.println("\n\n------ END OF PROCESSING -------\n\n");
}
}
Here is the desired output:
---- PROCESSING FILE NAMES -----
File Information : SampleName
File Information : java
------ END OF PROCESSING -------
Output that I'm getting:
---- PROCESSING FILE NAMES -----
------ END OF PROCESSING -------
I'm wondering, although the string has a dot .
in it, yet the split()
method is not performing its functionality. Can anyone please help me to fix this?