Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String concat(String path1, String path2) {
        String result;
        if (path2.startsWith("/") && path1.endsWith("/"))
            result = path1 + path2.substring(1);
        else if (path2.startsWith("/") || path1.endsWith("/"))
            result = path1 + path2;
        else
            result = path1 + "/" + path2;
        int i;
        while ((i = result.indexOf("/./")) >= 0)
            result = result.substring(0, i) + result.substring(i + 2);
        while (result.startsWith("./"))
            result = result.substring(2);
        while (result.endsWith("/."))
            result = result.substring(0, result.length() - 2);
        if (result.isEmpty())
            result = "/";
        return result;
    }
}