Java Utililty Methods Path Concatenate

List of utility methods to do Path Concatenate

Description

The list of methods to do Path Concatenate are organized into topic(s).

Method

StringconcatPath(String path0, String path1)
concat Path
if (path0 == null || path0.length() == 0) {
    return path1;
if (path1 == null || path1.length() == 0) {
    return path0;
if (path0.endsWith("/")) {
    if (path1.startsWith("/")) {
...
StringconcatPath(String path1, String path2)
concat Path
if (path2 == null)
    return path1;
if (path1 == null)
    return path2;
StringBuilder sb = new StringBuilder(path1);
if (!path1.endsWith("/") && !path2.startsWith("/"))
    sb.append('/');
sb.append(path2);
...
StringconcatPath(String path1, String path2)
concat Path
if (path1.endsWith(SLASH)) {
    return path1 + removeFirstSlash(path2);
return path1 + path2;
StringconcatPath(String path1, String path2)
concat Path
StringBuffer sb = new StringBuffer();
sb.append("/");
if (path1 != null && !path1.isEmpty()) {
    if (path1.startsWith("/")) {
        sb.append(path1.substring(1, path1.length()));
    } else {
        sb.append(path1);
    if (!path1.endsWith("/")) {
        sb.append("/");
if (path2 != null && !path2.isEmpty()) {
    if (path2.startsWith("/")) {
        sb.append(path2.substring(1, path2.length()));
    } else {
        sb.append(path2);
return sb.toString();
StringconcatPath(String pathName, String name)
Concatenates specified path with name, and makes sure that only one path-separator is added.
if ((pathName == null) || (pathName.length() == 0)) {
    return name;
if ((name == null) || (name.length() == 0)) {
    return pathName;
StringBuffer result = new StringBuffer(160);
if (pathName.endsWith("/")) {
...
StringconcatPath(String root, String fragment)
Concatenates a path fragment to a root path.
while (root.endsWith("/")) {
    root = root.substring(0, root.length() - 1);
while (fragment.startsWith("/")) {
    fragment = fragment.substring(1);
return root + "/" + fragment;
StringconcatPath(String root, String node)
concat Path
if (root == null) {
    root = NODE_SEPERATOR;
if (!root.startsWith(NODE_SEPERATOR)) {
    throw new RuntimeException("path should be start with a /");
if (!root.endsWith(NODE_SEPERATOR)) {
    root = root + NODE_SEPERATOR;
...
StringconcatPath(String src, String dst)
concat Path
if (dst == null || dst.length() == 0)
    return src;
int slash = dst.indexOf('/');
int question = dst.indexOf('?');
int equal = dst.indexOf('=');
String sep = "";
if (slash == 0 || question == 0) {
} else if (slash != -1 || question != -1 || equal == -1) {
...
StringconcatPath(String... path)
concat Path
String finalPath = "";
for (String item : path) {
    if (item.startsWith("/")) {
        finalPath = finalPath.concat(item);
    } else {
        finalPath = finalPath.concat("/").concat(item);
return finalPath;
StringconcatPaths(String path1, String path2)
Concatenates two path strings.
path2 = path2 == null ? "" : path2;
if (path1 == null || path1.isEmpty() || "/".equals(path1)) {
    if (path2.isEmpty()) {
        return "/";
    if (path2.charAt(0) == '/') {
        return path2; 
    return new StringBuilder(path2.length() + 1).append('/').append(path2).toString();
if (path2.isEmpty()) {
    return path1;
if (path1.charAt(path1.length() - 1) == '/') {
    if (path2.charAt(0) == '/') {
        return new StringBuilder(path1.length() + path2.length() - 1).append(path1)
                .append(path2, 1, path2.length()).toString();
    return new StringBuilder(path1.length() + path2.length()).append(path1).append(path2).toString();
if (path2.charAt(0) == '/') {
    return path1 + path2;
return new StringBuilder(path1.length() + path2.length() + 1).append(path1).append('/').append(path2)
        .toString();