StringComparisonUtil implements Serializable { public static int difference(String str1, String str2) { if (str1 == null || str2 == null) { return 0; } int[] cpArray1 = stringToCodePointArray(str1); int[] cpArray2 = stringToCodePointArray(str2); int lengthToMatch = Math.min(cpArray1.length, cpArray2.length); int diff = 0; for (int i = 0; i < lengthToMatch; i++) { if (cpArray1[i] == cpArray2[i]) { diff++; } } return diff; } private  StringComparisonUtil(); static int difference(String str1, String str2); static StringBuilder getCommonCharacters(final String string1, final String string2, final int distanceSep); static int getPrefixLength(final String string1, final String string2);  }
@Test public void testDifference() { assertEquals(0, StringComparisonUtil.difference(null, str2)); assertEquals(0, StringComparisonUtil.difference(str1, null)); assertEquals(3, StringComparisonUtil.difference(str1, str2)); assertEquals(3, StringComparisonUtil.difference(str1, str3)); assertEquals(2, StringComparisonUtil.difference(str1, str4)); assertEquals(0, StringComparisonUtil.difference(str1, str5)); assertEquals(0, StringComparisonUtil.difference(" ", "")); assertEquals(1, StringComparisonUtil.difference(" ", " ")); assertEquals(0, StringComparisonUtil.difference(null, null)); assertEquals(2, StringComparisonUtil.difference(str6, str7)); assertEquals(1, StringComparisonUtil.difference(str8, str9)); assertEquals(0, StringComparisonUtil.difference(str8, str10)); assertEquals(0, StringComparisonUtil.difference(str8, str11)); assertEquals(1, StringComparisonUtil.difference(str10, str11)); assertEquals(2, StringComparisonUtil.difference("𠀠𠀡𠀢", "𠀠𠀡a")); assertEquals(3, StringComparisonUtil.difference("𠀐𠀑𠀒𠀓𠀔", "𠀐𠀑a𠀓b")); }