public class StringUtil extends Object
| Constructor and Description |
|---|
StringUtil() |
| Modifier and Type | Method and Description |
|---|---|
static int |
getLevenshteinDistance(String s,
String t)
Find the Levenshtein distance between two Strings.
|
static String |
joinQuotedString(String[] str,
String delimiter,
int initialIndex,
String quote)
Join an array of strings into a string.
|
static String |
joinString(Collection<?> str,
String delimiter,
int initialIndex)
Join an list of strings into a string.
|
static String |
joinString(int[] str,
String delimiter,
int initialIndex)
Join an array of strings into a string.
|
static String |
joinString(Object[] str,
String delimiter,
int initialIndex)
Join an array of strings into a string.
|
static String |
joinString(String[] str,
String delimiter)
Join an array of strings into a string.
|
static String |
joinString(String[] str,
String delimiter,
int initialIndex)
Join an array of strings into a string.
|
static <T extends Enum<?>> |
lookup(Map<String,T> lookup,
String name,
boolean fuzzy) |
static String |
trimLength(String str,
int len)
Trim a string if it is longer than a certain length.
|
public static String trimLength(String str, int len)
str - len - public static String joinString(String[] str, String delimiter, int initialIndex)
str - delimiter - initialIndex - public static String joinQuotedString(String[] str, String delimiter, int initialIndex, String quote)
str - delimiter - initialIndex - quote - public static String joinString(String[] str, String delimiter)
str - delimiter - public static String joinString(Object[] str, String delimiter, int initialIndex)
str - delimiter - initialIndex - public static String joinString(int[] str, String delimiter, int initialIndex)
str - delimiter - initialIndex - public static String joinString(Collection<?> str, String delimiter, int initialIndex)
str - delimiter - initialIndex - public static int getLevenshteinDistance(String s, String 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 previous implementation of the Levenshtein distance algorithm was from http://www.merriampark.com/ld.htm
Chas Emerick has written an implementation in Java, which avoids an OutOfMemoryError
which can occur when my Java implementation is used with very large strings.
This implementation of the Levenshtein distance algorithm
is from http://www.merriampark.com/ldjava.htm
StringUtil.getLevenshteinDistance(null, *) = IllegalArgumentException
StringUtil.getLevenshteinDistance(*, null) = IllegalArgumentException
StringUtil.getLevenshteinDistance("","") = 0
StringUtil.getLevenshteinDistance("","a") = 1
StringUtil.getLevenshteinDistance("aaapppp", "") = 7
StringUtil.getLevenshteinDistance("frog", "fog") = 1
StringUtil.getLevenshteinDistance("fly", "ant") = 3
StringUtil.getLevenshteinDistance("elephant", "hippo") = 7
StringUtil.getLevenshteinDistance("hippo", "elephant") = 7
StringUtil.getLevenshteinDistance("hippo", "zzzzzzzz") = 8
StringUtil.getLevenshteinDistance("hello", "hallo") = 1
s - the first String, must not be nullt - the second String, must not be nullIllegalArgumentException - if either String input nullCopyright © 2010-2014. All Rights Reserved.