There are several ways to measure the distance between two strings. In this recipe, we will demonstrate how to use the Apache Commons Text library to compute the Hamming and Levenshtein distances.
Distance is concerned with the number of operations needed to convert one string into another string. These operations can be either single-character deletion, insertion, or substitution.
The Hamming distance algorithm works on strings of equal length, which may limit its utility in some situations. It simply measures the number of positions in the two strings that differ. It is case-sensitive.
The HammingDistance class possesses a single default constructor and an apply method, which takes two strings as its arguments. The method returns the distance between the strings.
A more detailed Hamming distance explanation can be found at http://en.wikipedia...