code: public static String parentResourceIdFromResourceId(String id) {
          if (id == null) {
              return null;
          }
          ResourceId resourceId = ResourceId.fromString(id);
          if (resourceId != null && resourceId.parent() != null) {
              return ResourceId.fromString(id).parent().id();
          }
  
          return null;
      }
docs: Extract parent resource ID from a resource ID string.
  E.g. subscriptions/s/resourcegroups/r/foos/foo/bars/bar will return
  subscriptions/s/resourcegroups/r/foos/foo.
  
  @param id the resource ID string
  @return the parent resource ID