Java String Difference difference(String xpath1, String xpath2)

Here you can find the source of difference(String xpath1, String xpath2)

Description

difference

License

Open Source License

Declaration

public static String difference(String xpath1, String xpath2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String difference(String xpath1, String xpath2) {
        String[] paths1 = split(xpath1);
        String[] paths2 = split(xpath2);
        int length = Math.min(paths1.length, paths2.length);
        int index = 0;
        while (index < length && paths1[index].equals(paths2[index])) {
            index++;//  ww w.  ja  v  a2  s. c o m
        }
        StringBuffer b = new StringBuffer();
        for (int i = 0; i < index; i++) {
            b.append(paths1[i]);
        }
        while (index < paths1.length) {
            b.append(paths1[index++]);
            b.append('/');
        }
        return b.toString();
    }

    public static String[] split(String xpath) {
        String[] paths = xpath.split("/");
        if (paths.length == 0) {
            paths = new String[1];
            paths[0] = "";
        }
        return paths;
    }
}

Related

  1. difference(String str1, String str2)
  2. difference(String str1, String str2)
  3. difference(String str1, String str2)
  4. difference(String str1, String str2)
  5. difference(String string1, String string2)
  6. differenceAt(String s1, String s2)
  7. differenceEncoded(String es1, String es2)
  8. differenceEncoded(String es1, String es2)