Search code examples
javaandroidstringlevenshtein-distance

Shortest Levenshtein Distance? Do I need it?


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.)


Solution

  • 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