Here you can find the source of findMaxCommonPrefix(String path1, String path2)
public static String findMaxCommonPrefix(String path1, String path2)
//package com.java2s; /* J_LZ_COPYRIGHT_BEGIN ******************************************************* * Copyright 2001-2011 Laszlo Systems, Inc. All Rights Reserved. * * Use is subject to license terms. * * J_LZ_COPYRIGHT_END *********************************************************/ public class Main { /**/* www . j av a2 s . c o m*/ Find maximum common prefix of path1 and path2 */ public static String findMaxCommonPrefix(String path1, String path2) { int i = 0; int len1 = path1.length(); int len2 = path2.length(); while ((i < len1) && (i < len2)) { if (path1.charAt(i) != path2.charAt(i)) { break; } i++; } if (i > 1 && path1.charAt(i - 1) == '/') { return path1.substring(0, i - 1); } else { return path1.substring(0, i); } } }