code: public static String getFirstPathComponent(String path) {
          int sIdx = path.indexOf('/');
  
          //path has no /'s ? return path.
          if (sIdx == -1) {
              return path;
          }
          //path has 1 char or less, (if 1, must be a '/' by previous if), return ""
          if (path.length() <= 1) {
              return "";
          }
          //path has more than 1 char, starts with /, has no other /'s, return path without leading /.
          if (sIdx == 0 && path.indexOf('/', 1) == -1) {
              return path.substring(1);
          }
  
          if (sIdx != 0) {
              //path does not start with /, but has / present.
              //return up to but not including 1st / position.
              return path.substring(0, sIdx);
          } else {
              //path starts with /, has multiple /'s present
              //remove 1st char and return up to but not including 1st / position.
              return path.substring(1, path.indexOf('/', 1));
          }
  
      }
docs: Answer the first file name of a path, using the forward slash character ('/')
  as the path separator character. Answer the path element which follows the last
  forward slash of the path.
  
  Answer the entire path if the path contains no path separator.
  
  Answer the path element which precedes the first path separator,
  except, ignore a leading path separator.
  
  For example:
  
  For "/parent/child" answer "parent".
  
  For "parent/child" answer "parent".
  
  For "parent" answer "parent".
  
  For "/parent" answer "parent".
  
  For "/" answer "".
  
  @param path The path from which to answer the first file name.
  An exception will be thrown if the path is null.
  
  @return The first file name of the path.