The only place you get an empty string (in a valid path) will be the first element if the path starts with a delimiter. If he had a leading delimiter, split his path without him.
String path = "/a/b/c";
String[] directories = path.substring(1).split(DIRECTORY_PATH_SEPARATOR);
OmnipotentEntity, . split().
String path = "/a/b////c";
String[] split = path.split(DIRECTORY_PATH_SEPARATOR);
ArrayList<String> directories = new ArrayList<String>(split.length);
for (String dir : split)
if (dir.length() > 0)
directories.add(dir);
:
String path = "/a/b////c";
ArrayList<String> directories = new ArrayList<String>();
Pattern regex = Pattern.compile("[^" + DIRECTORY_PATH_SEPARATOR + "]+");
Matcher matcher = regex.matcher(path);
while (matcher.find())
directories.add(matcher.group());