public class StringUtils extends Object
The library can be found here: https://commons.apache.org/proper/commons-lang/
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
getLevenshteinDistance(CharSequence s,
CharSequence t)
Find the Levenshtein distance between two Strings.
|
public static int getLevenshteinDistance(CharSequence s, CharSequence t)
Find the Levenshtein distance between two Strings.
This is the number of changes needed to change one String into another, where each change is a single character modification (deletion, insertion or substitution).
The implementation uses a single-dimensional array of length s.length() + 1. See http://blog.softwx.net/2014/12/optimizing-levenshtein-algorithm-in-c.html for details.
StringUtils.getLevenshteinDistance(null, *) = IllegalArgumentException StringUtils.getLevenshteinDistance(*, null) = IllegalArgumentException StringUtils.getLevenshteinDistance("","") = 0 StringUtils.getLevenshteinDistance("","a") = 1 StringUtils.getLevenshteinDistance("aaapppp", "") = 7 StringUtils.getLevenshteinDistance("frog", "fog") = 1 StringUtils.getLevenshteinDistance("fly", "ant") = 3 StringUtils.getLevenshteinDistance("elephant", "hippo") = 7 StringUtils.getLevenshteinDistance("hippo", "elephant") = 7 StringUtils.getLevenshteinDistance("hippo", "zzzzzzzz") = 8 StringUtils.getLevenshteinDistance("hello", "hallo") = 1
s
- the first String, must not be nullt
- the second String, must not be nullIllegalArgumentException
- if either String input null
Copyright © 2012–2019. All rights reserved.