code: public static String getParentPath(String path) {
          if (path == null) return null;
          path = path.trim();
          if (path.endsWith(PATH_ROOT) && path.length() > 1) {
              path = path.substring(0, path.length() - 1);
          }
          int lastIndex = path.lastIndexOf(PATH_ROOT);
          if (path.length() > 1 && lastIndex > 0) {
              return path.substring(0, lastIndex);
          }
          return PATH_ROOT;
      }
docs: Fast get parent directory using substring
  
  @param path path whose parent path has to be returned
  @return parent path of the argument