Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static String[] components(String path, String separator) { if (path == null || path.isEmpty()) return null; String[] tmp = path.split(separator + "+"); // multiple separators could be present if (tmp == null) return null; if (tmp.length == 0) return null; if (tmp[0].isEmpty()) tmp[0] = separator; return tmp; } }