Java Array Max Value findMaxCommonPrefix(String path1, String path2)

Here you can find the source of findMaxCommonPrefix(String path1, String path2)

Description

Find maximum common prefix of path1 and path2

License

Open Source License

Declaration

public static String findMaxCommonPrefix(String path1, String path2) 

Method Source Code

//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);
        }

    }
}

Related

  1. findMax(int[] v)
  2. findMax(int[] workArray, int idx)
  3. findMax(T[] arr)
  4. findMax2(int[] workArray, int idx, int max)
  5. findMaxAbs(float[] array)
  6. findMaxDiff(byte[] rand, byte[] newRand)
  7. findMaximumUnitFor(long elapsed, int specifiedMax)
  8. findMaxIndex(final int[] array)
  9. findMaxIndex(int[] a)