Java Utililty Methods String Difference

List of utility methods to do String Difference

Description

The list of methods to do String Difference are organized into topic(s).

Method

Stringdifference(String s1, String s2)
Compare two strings, and return the portion where they differ.
int at = differenceAt(s1, s2);
if (at == -1) {
    return "";
return s2.substring(at);
intdifference(String str1, String str2)
Returns the number of characters in the two Strings that are the same.
if (str1 == null || str2 == null) {
    return 0;
int lengthToMatch = Math.min(str1.length(), str2.length());
int diff = 0;
for (int i = 0; i < lengthToMatch; i++) {
    if (str1.charAt(i) == str2.charAt(i)) {
        diff++;
...
Stringdifference(String str1, String str2)
difference
if (str1 == null) {
    return str2;
if (str2 == null) {
    return str1;
int at = indexOfDifference(str1, str2);
if (at == -1) {
...
Stringdifference(String str1, String str2)
difference
if (str1 == null) {
    return str2;
if (str2 == null) {
    return str1;
int at = indexOfDifference(str1, str2);
if (at == -1) {
...
Stringdifference(String str1, String str2)
difference
if (str1 == null) {
    return str2;
if (str2 == null) {
    return str1;
int at = indexOfDifference(str1, str2);
if (at == INDEX_NOT_FOUND) {
...
Stringdifference(String str1, String str2)

Compares two Strings, and returns the portion where they differ.

if (str1 == null)
    return str2;
if (str2 == null)
    return str1;
int at = indexOfDifference(str1, str2);
if (at == -1)
    return EMPTY;
return str2.substring(at);
...
booleandifference(String string1, String string2)
difference
boolean res = false;
if (string1 != null && string2 == null) {
    res = true;
} else if (string1 == null && string2 != null) {
    res = true;
} else if (string1 != null && string2 != null) {
    if (!string1.equalsIgnoreCase(string2)) {
        res = true;
...
Stringdifference(String xpath1, String xpath2)
difference
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++;
StringBuffer b = new StringBuffer();
...
intdifferenceAt(String s1, String s2)
Compare two strings, and return the index at which the strings begin to differ.
int i;
for (i = 0; (i < s1.length()) && (i < s2.length()); ++i) {
    if (s1.charAt(i) != s2.charAt(i)) {
        break;
if ((i < s2.length()) || (i < s1.length())) {
    return i;
...
intdifferenceEncoded(String es1, String es2)
Returns the number of characters in the two Soundex encoded Strings that are the same.
if (es1 == null || es2 == null) {
    return 0;
int lengthToMatch = Math.min(es1.length(), es2.length());
int diff = 0;
for (int i = 0; i < lengthToMatch; i++) {
    if (es1.charAt(i) == es2.charAt(i)) {
        diff++;
...