public default Path subPath(final String fromLabel, final String toLabel) {
        if (null == fromLabel && null == toLabel)
            return this;
        else {
            Path subPath = MutablePath.make();
            final int size = this.size();
            int fromIndex = -1;
            int toIndex = -1;
            for (int i = size - 1; i >= 0; i--) {
                final Set<String> labels = this.labels().get(i);
                if (-1 == fromIndex && labels.contains(fromLabel))
                    fromIndex = i;
                if (-1 == toIndex && labels.contains(toLabel))
                    toIndex = i;
            }
            if (null != fromLabel && -1 == fromIndex)
                throw Path.Exceptions.couldNotLocatePathFromLabel(fromLabel);
            if (null != toLabel && -1 == toIndex)
                throw Path.Exceptions.couldNotLocatePathToLabel(toLabel);

            if (fromIndex == -1)
                fromIndex = 0;
            if (toIndex == -1)
                toIndex = size-1;
            if (fromIndex > toIndex)
                throw Path.Exceptions.couldNotIsolatedSubPath(fromLabel, toLabel);
            for (int i = fromIndex; i <= toIndex; i++) {
                final Set<String> labels = this.labels().get(i);
                subPath.extend(this.get(i), labels);
            }
            return subPath;
        }
    }
Isolate a sub-path from the path object. The isolation is based solely on the path labels.
The to-label is inclusive. Thus, from "b" to "c" would isolate the example path as follows {@code a,[b,c],d}.
Note that if there are multiple path segments with the same label, then its the last occurrence that is isolated.
For instance, from "b" to "c" would be {@code a,b,[b,c,d,c]}.

@param fromLabel The label to start recording the sub-path from.
@param toLabel   The label to end recording the sub-path to.
@return the isolated sub-path.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java