commons-text.commons-lang.lang minimally remains all that every Java developer needs.text in the sandbox.
text where they left off, and by March 11, 2017
we had our 1.0.
lang's StringUtils:StrBuilder, FormattableUtils, StrSubstitutor, and
StrTokenizerlangStrBuilderjava.lang.StringBuilderStrBuilder sb = new StrBuilder("Test");
sb.readFrom(CharBuffer.wrap(" 123")); // "Test 123"
sb = new StrBuilder("bb");
sb.replaceAll("b", "xbx"); // "xbxxbx"
sb = new StrBuilder("abc");
sb.replace(0, 1, "aaa"); // "aaabc"
FormattableUtilsjava.util.FormatterFormattableUtils.append("foo",
new Formatter(),
FormattableFlags.LEFT_JUSTIFY,
6, -1, '*').toString(); // "foo***"
FormattableUtils.append("foo",
new Formatter(),
FormattableFlags.LEFT_JUSTIFY,
6, -1).toString(); // "foo "
StrSubstitutorMap valuesMap = HashMap();
valuesMap.put("animal", "quick brown fox");
valuesMap.put("target", "lazy dog");
String templateString = "The ${animal} jumped " +
"over the ${target}.";
StrSubstitutor sub = new StrSubstitutor(valuesMap);
String resolvedString = sub.replace(templateString);
// "The quick brown fox jumped over the lazy dog."
StrTokenizerjava.util.StringTokenizerjava.util.ListIterator interface
StrTokenizerfinal String input = "a;b;c;\"d;e\";f; ; ; ";
final StrTokenizer tok = new StrTokenizer(input);
tok.setDelimiterChar(';');
tok.setQuoteChar('"');
//Matches the String trim() whitespace characters.
tok.setIgnoredMatcher(StrMatcher.trimMatcher());
tok.setIgnoreEmptyTokens(false);
final String tokens[] = tok.getTokenArray();
// String[]{"a", "b", "c", "d;e", "f", "", "", ""};
StringEscapeUtilsStringEscapeUtils.escapeJson("He didn't say, \"stop!\"");
// "He didn\\'t say, \\\"stop!\\\""
StringEscapeUtils.escapeJava("\\\b\t\r");
// "\\\\\\b\\t\\r"
textLongestCommonSubsequenceThe Longest commons subsequence is a classical String similarity algorithm.
LongestCommonSubsequence siml =
new LongestCommonsSubsequence();
siml.apply("abba","abab"); // 3
siml.apply("frog", "fog"); // 3
siml.apply("PENNSYLVANIA", "PENNCISYLVNIA"); // 11
smil.apply("elephant", "hippo"); // 1
LongestCommonSubsequenceDistanceLongestCommonSubsequenceDistance dist =
new LongestCommonSubsequenceDistance();
dist.apply("abba","abab"); // 2
dist.apply("frog", "fog"); // 1
dist.apply("PENNSYLVANIA", "PENNCISYLVNIA"); // 3
dist.apply("elephant", "hippo"); // 11
LevenshteinDistanceDifferent algorithm with almost the same results.
LevenshteinDistance dist = new LevenshteinDistance();
dist.apply("abba","abab"); // 2
dist.apply("frog", "fog"); // 1
dist.apply("PENNSYLVANIA", "PENNCISYLVNIA"); // 3
dist.apply("elephant", "hippo"); // 7
org.apache.commons.text.diff contains the a variety of diff tools.org.apache.commons.text.similarity contains various other similarity/distance toolsorg.apache.commons.text.translate mainly supports StringEscapeUtils, but has more...WordUtils from lang, with some updates.RandomStringGenerator thanks to the rng crew.@Deprecated on code taken from lang