猿问

如何在Java中执行字符串比较?

我需要在Java字符串之间执行Diffs。我希望能够使用原始的string和diff版本重建字符串。有人用Java完成吗?您使用什么图书馆?


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


30秒到达战场
浏览 453回答 3
3回答

小唯快跑啊

Apache Commons具有String difforg.apache.commons.lang.StringUtilsStringUtils.difference("foobar", "foo");

FFIVE

正如Torsten所说,您可以使用org.apache.commons.lang.StringUtils;System.err.println(StringUtils.getLevenshteinDistance("foobar", "bar"));
随时随地看视频慕课网APP

相关分类

Java
我要回答