I want to look up a String
in a String[]
for the best match of the query. I have heard of Levenshtein Distance. But I cannot determine if I need it or not.
Suppose, I have a String query = "Examples"
and
String[] arrayStr = new String[] {"The Examples String", "The Example String", "Example", "Examples String", "Example String", "Examplestring"};
Now, I want to get the Example
from the String[]
as the best match.
So, Do I need Levenshtein Distance to do it?
Alternatively, If someone can point me a fast implementation of Levenshtein Distance for Java, it would be great. I would like to check if it works with all the kind of strings that I have. (Basically I have around 10k strings to match from 10k arrays.)
Yes, Levenshtein Distance is the goto algorithm for this. You can find implementations in many languages, including Java, at http://rosettacode.org/wiki/Levenshtein_distance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With