Here you can find the source of subtractPaths(String longPath, String shortPath)
public static String subtractPaths(String longPath, String shortPath)
//package com.java2s; /*//from w w w. j a v a 2 s . c o m * This file is part of MML. * * MML is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MML is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MML. If not, see <http://www.gnu.org/licenses/>. * (c) copyright Desmond Schmidt 2014 */ public class Main { public static String subtractPaths(String longPath, String shortPath) { StringBuilder sb = new StringBuilder(); String[] parts1 = longPath.split("/"); String[] parts2 = shortPath.split("/"); for (int i = 0; i < parts1.length; i++) { if (i >= parts2.length || !parts1[i].equals(parts2[i])) { for (int j = i; j < parts1.length; j++) { if (sb.length() > 0) sb.append("/"); sb.append(parts1[j]); } break; } } return sb.toString(); } }