我需要在Java字符串之間執行Diffs。我希望能夠從原始字符串和diff版本重建字符串。有沒有人在Java中這樣做過?你使用什麼庫?如何在Java中執行字符串Diffs?
String a1; // This can be a long text
String a2; // ej. above text with spelling corrections
String a3; // ej. above text with spelling corrections and an additional sentence
Diff diff = new Diff();
String differences_a1_a2 = Diff.getDifferences(a,changed_a);
String differences_a2_a3 = Diff.getDifferences(a,changed_a);
String[] diffs = new String[]{a,differences_a1_a2,differences_a2_a3};
String new_a3 = Diff.build(diffs);
a3.equals(new_a3); // this is true
另見http://stackoverflow.com/questions/479654/java-library-for-free-text-diff – Stewart 2013-06-17 16:40:37