Class StringUtils
- java.lang.Object
- 
- software.amazon.smithy.utils.StringUtils
 
- 
 public final class StringUtils extends java.lang.ObjectOperations on Stringthat arenullsafe.- IsEmpty/IsBlank - checks if a String contains text
- Trim - removes leading and trailing whitespace
- Equals/Compare - compares two strings null-safe
- Substring - null-safe substring extraction
- UpperCase/LowerCase/Capitalize/Uncapitalize - changes the case of a String
 The StringUtilsclass defines certain words related to String handling.- null - null
- empty - a zero-length string ("")
- space - the space character (' ', char 32)
- whitespace - the characters defined by Character.isWhitespace(char)
- trim - the characters <= 32 as in String.trim()
 StringUtilshandlesnullinput Strings quietly. That is to say that anullinput will returnnull. Where abooleanorintis being returned details vary by method.A side effect of the nullhandling is that aNullPointerExceptionshould be considered a bug inStringUtils.This class's source was modified from the Apache commons-lang and Apache commons-text libraries: https://github.com/apache/commons-lang/, https://github.com/apache/commons-text/ #ThreadSafe# - See Also:
- String, Apache Commons Lang, Apache Commons Text , Elephant bird license
 
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringcapitalize(java.lang.String str)Capitalizes a String changing the first character to title case as perCharacter.toTitleCase(int).static booleanequals(java.lang.String cs1, java.lang.String cs2)Compares two Strings, returningtrueif they represent equal sequences of characters.static java.lang.StringescapeJavaString(java.lang.Object object, java.lang.String indent)static java.lang.Stringindent(java.lang.String string, int spaces)Indents each line in the provided string by the provided number of spaces.static booleanisBlank(java.lang.CharSequence cs)Checks if a CharSequence is empty (""), null or whitespace only.static booleanisEmpty(java.lang.CharSequence cs)Checks if a CharSequence is empty ("") or null.static booleanisNotBlank(java.lang.CharSequence cs)Checks if a CharSequence is not empty (""), not null and not whitespace only.static java.lang.StringleftPad(java.lang.String str, int size)Left pad a String with spaces (' ').static java.lang.StringleftPad(java.lang.String str, int size, char padChar)Left pad a String with a specified character.static java.lang.StringleftPad(java.lang.String str, int size, java.lang.String padStr)Left pad a String with a specified String.static intlevenshteinDistance(java.lang.CharSequence left, java.lang.CharSequence right, int threshold)Find the Levenshtein distance between two CharSequences if it's less than or equal to a given threshold.static java.lang.StringlowerCase(java.lang.String str)Converts a String to lower case as perString.toLowerCase().static java.lang.Stringrepeat(char ch, int repeat)Returns padding using the specified delimiter repeated to a given length.static java.lang.Stringrepeat(java.lang.String str, int repeat)Repeat a Stringrepeattimes to form a new String.static java.lang.StringrightPad(java.lang.String str, int size)Right pad a String with spaces (' ').static java.lang.StringrightPad(java.lang.String str, int size, char padChar)Right pad a String with a specified character.static java.lang.StringrightPad(java.lang.String str, int size, java.lang.String padStr)Right pad a String with a specified String.static booleanstartsWithIgnoreCase(java.lang.String str, java.lang.String prefix)Tests if this string starts with the specified prefix ignoring case considerations.static java.lang.Stringstrip(java.lang.String str, java.lang.String stripChars)Strips any of a set of characters from the start and end of a String.static java.lang.StringstripEnd(java.lang.String str, java.lang.String stripChars)Strips any of a set of characters from the end of a String.static java.lang.StringstripStart(java.lang.String str, java.lang.String stripChars)Strips any of a set of characters from the start of a String.static java.lang.StringstripToEmpty(java.lang.String str)Strips whitespace from the start and end of a String returning an empty String ifnullinput.static java.lang.Stringsubstring(java.lang.String str, int start)Gets a substring from the specified String avoiding exceptions.static java.lang.Stringsubstring(java.lang.String str, int start, int end)Gets a substring from the specified String avoiding exceptions.static java.lang.Stringtrim(java.lang.String str)Removes control characters (char <= 32) from both ends of this String, handlingnullby returningnull.static java.lang.StringtrimToEmpty(java.lang.String str)Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it isnull.static java.lang.StringtrimToNull(java.lang.String str)Removes control characters (char <= 32) from both ends of this String returningnullif the String is empty ("") after the trim or if it isnull.static java.lang.Stringuncapitalize(java.lang.String str)Uncapitalizes a String, changing the first character to lower case as perCharacter.toLowerCase(int).static java.lang.StringupperCase(java.lang.String str)Converts a String to upper case as perString.toUpperCase().static java.lang.Stringwrap(java.lang.String str, int wrapLength)Wraps a single line of text, identifying words by' '.static java.lang.Stringwrap(java.lang.String str, int wrapLength, java.lang.String newLineStr, boolean wrapLongWords)Wraps a single line of text, identifying words by' '.static java.lang.Stringwrap(java.lang.String str, int wrapLength, java.lang.String newLineStr, boolean wrapLongWords, java.lang.String wrapOn)Wraps a single line of text, identifying words bywrapOn.
 
- 
- 
- 
Method Detail- 
isEmptypublic static boolean isEmpty(java.lang.CharSequence cs) Checks if a CharSequence is empty ("") or null. StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = falseNOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank(). - Parameters:
- cs- the CharSequence to check, may be null
- Returns:
- trueif the CharSequence is empty or null
- Since:
- 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
- See Also:
- Source
 
 - 
isBlankpublic static boolean isBlank(java.lang.CharSequence cs) Checks if a CharSequence is empty (""), null or whitespace only. Whitespace is defined by Character.isWhitespace(char).StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false- Parameters:
- cs- the CharSequence to check, may be null
- Returns:
- trueif the CharSequence is null, empty or whitespace only
- Since:
- 2.0, 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
- See Also:
- Source
 
 - 
isNotBlankpublic static boolean isNotBlank(java.lang.CharSequence cs) Checks if a CharSequence is not empty (""), not null and not whitespace only. Whitespace is defined by Character.isWhitespace(char).StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true- Parameters:
- cs- the CharSequence to check, may be null
- Returns:
- trueif the CharSequence is not empty and not null and not whitespace only
- Since:
- 2.0, 3.0 Changed signature from isNotBlank(String) to isNotBlank(CharSequence)
- See Also:
- Source
 
 - 
trimpublic static java.lang.String trim(java.lang.String str) Removes control characters (char <= 32) from both ends of this String, handling nullby returningnull.The String is trimmed using String.trim(). Trim removes start and end characters <= 32.StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"- Parameters:
- str- the String to be trimmed, may be null
- Returns:
- the trimmed string, nullif null String input
- See Also:
- Source
 
 - 
trimToNullpublic static java.lang.String trimToNull(java.lang.String str) Removes control characters (char <= 32) from both ends of this String returning nullif the String is empty ("") after the trim or if it isnull.The String is trimmed using String.trim(). Trim removes start and end characters <= 32.StringUtils.trimToNull(null) = null StringUtils.trimToNull("") = null StringUtils.trimToNull(" ") = null StringUtils.trimToNull("abc") = "abc" StringUtils.trimToNull(" abc ") = "abc"- Parameters:
- str- the String to be trimmed, may be null
- Returns:
- the trimmed String,
  nullif only chars <= 32, empty or null String input
- Since:
- 2.0
- See Also:
- Source
 
 - 
trimToEmptypublic static java.lang.String trimToEmpty(java.lang.String str) Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null.The String is trimmed using String.trim(). Trim removes start and end characters <= 32.StringUtils.trimToEmpty(null) = "" StringUtils.trimToEmpty("") = "" StringUtils.trimToEmpty(" ") = "" StringUtils.trimToEmpty("abc") = "abc" StringUtils.trimToEmpty(" abc ") = "abc"- Parameters:
- str- the String to be trimmed, may be null
- Returns:
- the trimmed String, or an empty String if nullinput
- Since:
- 2.0
- See Also:
- Source
 
 - 
equalspublic static boolean equals(java.lang.String cs1, java.lang.String cs2)Compares two Strings, returning trueif they represent equal sequences of characters.nulls are handled without exceptions. Twonullreferences are considered to be equal. The comparison is case sensitive.StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false- Parameters:
- cs1- the first String, may be- null
- cs2- the second String, may be- null
- Returns:
- trueif the Strings are equal (case-sensitive), or both- null
- See Also:
- Object.equals(Object), Source
 
 - 
substringpublic static java.lang.String substring(java.lang.String str, int start)Gets a substring from the specified String avoiding exceptions. A negative start position can be used to start ncharacters from the end of the String.A nullString will returnnull. An empty ("") String will return "".StringUtils.substring(null, *) = null StringUtils.substring("", *) = "" StringUtils.substring("abc", 0) = "abc" StringUtils.substring("abc", 2) = "c" StringUtils.substring("abc", 4) = "" StringUtils.substring("abc", -2) = "bc" StringUtils.substring("abc", -4) = "abc"- Parameters:
- str- the String to get the substring from, may be null
- start- the position to start from, negative means count back from the end of the String by this many characters
- Returns:
- substring from start position, nullif null String input
- See Also:
- Source
 
 - 
substringpublic static java.lang.String substring(java.lang.String str, int start, int end)Gets a substring from the specified String avoiding exceptions. A negative start position can be used to start/end ncharacters from the end of the String.The returned substring starts with the character in the startposition and ends before theendposition. All position counting is zero-based -- i.e., to start at the beginning of the string usestart = 0. Negative start and end positions can be used to specify offsets relative to the end of the String.If startis not strictly to the left ofend, "" is returned.StringUtils.substring(null, *, *) = null StringUtils.substring("", * , *) = ""; StringUtils.substring("abc", 0, 2) = "ab" StringUtils.substring("abc", 2, 0) = "" StringUtils.substring("abc", 2, 4) = "c" StringUtils.substring("abc", 4, 6) = "" StringUtils.substring("abc", 2, 2) = "" StringUtils.substring("abc", -2, -1) = "b" StringUtils.substring("abc", -4, 2) = "ab"- Parameters:
- str- the String to get the substring from, may be null
- start- the position to start from, negative means count back from the end of the String by this many characters
- end- the position to end at (exclusive), negative means count back from the end of the String by this many scharacters
- Returns:
- substring from start position to end position,
  nullif null String input
- See Also:
- Source
 
 - 
upperCasepublic static java.lang.String upperCase(java.lang.String str) Converts a String to upper case as per String.toUpperCase().A nullinput String returnsnull.StringUtils.upperCase(null) = null StringUtils.upperCase("") = "" StringUtils.upperCase("aBc") = "ABC"This uses "ENGLISH" as the locale. - Parameters:
- str- the String to upper case, may be null
- Returns:
- the upper cased String, nullif null String input
- See Also:
- Source
 
 - 
lowerCasepublic static java.lang.String lowerCase(java.lang.String str) Converts a String to lower case as per String.toLowerCase().A nullinput String returnsnull.StringUtils.lowerCase(null) = null StringUtils.lowerCase("") = "" StringUtils.lowerCase("aBc") = "abc"This uses "ENGLISH" as the locale. - Parameters:
- str- the String to lower case, may be null
- Returns:
- the lower cased String, nullif null String input
- See Also:
- Source
 
 - 
capitalizepublic static java.lang.String capitalize(java.lang.String str) Capitalizes a String changing the first character to title case as per Character.toTitleCase(int). No other characters are changed.StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt" StringUtils.capitalize("'cat'") = "'cat'"- Parameters:
- str- the String to capitalize, may be null
- Returns:
- the capitalized String, nullif null String input
- Since:
- 2.0
- See Also:
- uncapitalize(String), Source
 
 - 
uncapitalizepublic static java.lang.String uncapitalize(java.lang.String str) Uncapitalizes a String, changing the first character to lower case as per Character.toLowerCase(int). No other characters are changed.StringUtils.uncapitalize(null) = null StringUtils.uncapitalize("") = "" StringUtils.uncapitalize("cat") = "cat" StringUtils.uncapitalize("Cat") = "cat" StringUtils.uncapitalize("CAT") = "cAT"- Parameters:
- str- the String to uncapitalize, may be null
- Returns:
- the uncapitalized String, nullif null String input
- Since:
- 2.0
- See Also:
- capitalize(String), Source
 
 - 
startsWithIgnoreCasepublic static boolean startsWithIgnoreCase(java.lang.String str, java.lang.String prefix)Tests if this string starts with the specified prefix ignoring case considerations.- Parameters:
- str- the string to be tested
- prefix- the prefix
- Returns:
- true if the string starts with the prefix ignoring case
 
 - 
repeatpublic static java.lang.String repeat(java.lang.String str, int repeat)Repeat a String repeattimes to form a new String.StringUtils.repeat(null, 2) = null StringUtils.repeat("", 0) = "" StringUtils.repeat("", 2) = "" StringUtils.repeat("a", 3) = "aaa" StringUtils.repeat("ab", 2) = "abab" StringUtils.repeat("a", -2) = ""- Parameters:
- str- the String to repeat, may be null
- repeat- number of times to repeat str, negative treated as zero
- Returns:
- a new String consisting of the original String repeated,
  nullif null String input
- See Also:
- Source
 
 - 
repeatpublic static java.lang.String repeat(char ch, int repeat)Returns padding using the specified delimiter repeated to a given length. StringUtils.repeat('e', 0) = "" StringUtils.repeat('e', 3) = "eee" StringUtils.repeat('e', -2) = ""Note: this method does not support padding with Unicode Supplementary Characters as they require a pair of chars to be represented. If you are needing to support full I18N of your applications consider usingrepeat(String, int)instead.- Parameters:
- ch- character to repeat
- repeat- number of times to repeat char, negative treated as zero
- Returns:
- String with repeated character
- See Also:
- repeat(String, int), Source
 
 - 
rightPadpublic static java.lang.String rightPad(java.lang.String str, int size)Right pad a String with spaces (' '). The String is padded to the size of size.StringUtils.rightPad(null, *) = null StringUtils.rightPad("", 3) = " " StringUtils.rightPad("bat", 3) = "bat" StringUtils.rightPad("bat", 5) = "bat " StringUtils.rightPad("bat", 1) = "bat" StringUtils.rightPad("bat", -1) = "bat"- Parameters:
- str- the String to pad out, may be null
- size- the size to pad to
- Returns:
- right padded String or original String if no padding is necessary,
  nullif null String input
- See Also:
- Source
 
 - 
rightPadpublic static java.lang.String rightPad(java.lang.String str, int size, char padChar)Right pad a String with a specified character. The String is padded to the size of size.StringUtils.rightPad(null, *, *) = null StringUtils.rightPad("", 3, 'z') = "zzz" StringUtils.rightPad("bat", 3, 'z') = "bat" StringUtils.rightPad("bat", 5, 'z') = "batzz" StringUtils.rightPad("bat", 1, 'z') = "bat" StringUtils.rightPad("bat", -1, 'z') = "bat"- Parameters:
- str- the String to pad out, may be null
- size- the size to pad to
- padChar- the character to pad with
- Returns:
- right padded String or original String if no padding is necessary,
  nullif null String input
- Since:
- 2.0
- See Also:
- Source
 
 - 
rightPadpublic static java.lang.String rightPad(java.lang.String str, int size, java.lang.String padStr)Right pad a String with a specified String. The String is padded to the size of size.StringUtils.rightPad(null, *, *) = null StringUtils.rightPad("", 3, "z") = "zzz" StringUtils.rightPad("bat", 3, "yz") = "bat" StringUtils.rightPad("bat", 5, "yz") = "batyz" StringUtils.rightPad("bat", 8, "yz") = "batyzyzy" StringUtils.rightPad("bat", 1, "yz") = "bat" StringUtils.rightPad("bat", -1, "yz") = "bat" StringUtils.rightPad("bat", 5, null) = "bat " StringUtils.rightPad("bat", 5, "") = "bat "- Parameters:
- str- the String to pad out, may be null
- size- the size to pad to
- padStr- the String to pad with, null or empty treated as single space
- Returns:
- right padded String or original String if no padding is necessary,
  nullif null String input
- See Also:
- Source
 
 - 
leftPadpublic static java.lang.String leftPad(java.lang.String str, int size)Left pad a String with spaces (' '). The String is padded to the size of size.StringUtils.leftPad(null, *) = null StringUtils.leftPad("", 3) = " " StringUtils.leftPad("bat", 3) = "bat" StringUtils.leftPad("bat", 5) = " bat" StringUtils.leftPad("bat", 1) = "bat" StringUtils.leftPad("bat", -1) = "bat"- Parameters:
- str- the String to pad out, may be null
- size- the size to pad to
- Returns:
- left padded String or original String if no padding is necessary,
  nullif null String input
- See Also:
- Source
 
 - 
leftPadpublic static java.lang.String leftPad(java.lang.String str, int size, char padChar)Left pad a String with a specified character. Pad to a size of size.StringUtils.leftPad(null, *, *) = null StringUtils.leftPad("", 3, 'z') = "zzz" StringUtils.leftPad("bat", 3, 'z') = "bat" StringUtils.leftPad("bat", 5, 'z') = "zzbat" StringUtils.leftPad("bat", 1, 'z') = "bat" StringUtils.leftPad("bat", -1, 'z') = "bat"- Parameters:
- str- the String to pad out, may be null
- size- the size to pad to
- padChar- the character to pad with
- Returns:
- left padded String or original String if no padding is necessary,
  nullif null String input
- Since:
- 2.0
- See Also:
- Source
 
 - 
leftPadpublic static java.lang.String leftPad(java.lang.String str, int size, java.lang.String padStr)Left pad a String with a specified String. Pad to a size of size.StringUtils.leftPad(null, *, *) = null StringUtils.leftPad("", 3, "z") = "zzz" StringUtils.leftPad("bat", 3, "yz") = "bat" StringUtils.leftPad("bat", 5, "yz") = "yzbat" StringUtils.leftPad("bat", 8, "yz") = "yzyzybat" StringUtils.leftPad("bat", 1, "yz") = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null) = " bat" StringUtils.leftPad("bat", 5, "") = " bat"- Parameters:
- str- the String to pad out, may be null
- size- the size to pad to
- padStr- the String to pad with, null or empty treated as single space
- Returns:
- left padded String or original String if no padding is necessary,
  nullif null String input
- See Also:
- Source
 
 - 
strippublic static java.lang.String strip(java.lang.String str, java.lang.String stripChars)Strips any of a set of characters from the start and end of a String. This is similar to String.trim()but allows the characters to be stripped to be controlled.A nullinput String returnsnull. An empty string ("") input returns the empty string.If the stripChars String is null, whitespace is stripped as defined byCharacter.isWhitespace(char).StringUtils.strip(null, *) = null StringUtils.strip("", *) = "" StringUtils.strip("abc", null) = "abc" StringUtils.strip(" abc", null) = "abc" StringUtils.strip("abc ", null) = "abc" StringUtils.strip(" abc ", null) = "abc" StringUtils.strip(" abcyx", "xyz") = " abc"- Parameters:
- str- the String to remove characters from, may be null
- stripChars- the characters to remove, null treated as whitespace
- Returns:
- the stripped String, nullif null String input
- See Also:
- Source
 
 - 
stripEndpublic static java.lang.String stripEnd(java.lang.String str, java.lang.String stripChars)Strips any of a set of characters from the end of a String. A nullinput String returnsnull. An empty string ("") input returns the empty string.If the stripChars String is null, whitespace is stripped as defined byCharacter.isWhitespace(char).StringUtils.stripEnd(null, *) = null StringUtils.stripEnd("", *) = "" StringUtils.stripEnd("abc", "") = "abc" StringUtils.stripEnd("abc", null) = "abc" StringUtils.stripEnd(" abc", null) = " abc" StringUtils.stripEnd("abc ", null) = "abc" StringUtils.stripEnd(" abc ", null) = " abc" StringUtils.stripEnd(" abcyx", "xyz") = " abc" StringUtils.stripEnd("120.00", ".0") = "12"- Parameters:
- str- the String to remove characters from, may be null
- stripChars- the set of characters to remove, null treated as whitespace
- Returns:
- the stripped String, nullif null String input
- See Also:
- Source
 
 - 
stripStartpublic static java.lang.String stripStart(java.lang.String str, java.lang.String stripChars)Strips any of a set of characters from the start of a String. A nullinput String returnsnull. An empty string ("") input returns the empty string.If the stripChars String is null, whitespace is stripped as defined byCharacter.isWhitespace(char).StringUtils.stripStart(null, *) = null StringUtils.stripStart("", *) = "" StringUtils.stripStart("abc", "") = "abc" StringUtils.stripStart("abc", null) = "abc" StringUtils.stripStart(" abc", null) = "abc" StringUtils.stripStart("abc ", null) = "abc " StringUtils.stripStart(" abc ", null) = "abc " StringUtils.stripStart("yxabc ", "xyz") = "abc "- Parameters:
- str- the String to remove characters from, may be null
- stripChars- the characters to remove, null treated as whitespace
- Returns:
- the stripped String, nullif null String input
- See Also:
- Source
 
 - 
stripToEmptypublic static java.lang.String stripToEmpty(java.lang.String str) Strips whitespace from the start and end of a String returning an empty String if nullinput.This is similar to trimToEmpty(String)but removes whitespace. Whitespace is defined byCharacter.isWhitespace(char).StringUtils.stripToEmpty(null) = "" StringUtils.stripToEmpty("") = "" StringUtils.stripToEmpty(" ") = "" StringUtils.stripToEmpty("abc") = "abc" StringUtils.stripToEmpty(" abc") = "abc" StringUtils.stripToEmpty("abc ") = "abc" StringUtils.stripToEmpty(" abc ") = "abc" StringUtils.stripToEmpty(" ab c ") = "ab c"- Parameters:
- str- the String to be stripped, may be null
- Returns:
- the trimmed String, or an empty String if nullinput
- Since:
- 2.0
- See Also:
- Source
 
 - 
wrappublic static java.lang.String wrap(java.lang.String str, int wrapLength)Wraps a single line of text, identifying words by ' '.New lines will be separated by the system property line separator. Very long words, such as URLs will not be wrapped. Leading spaces on a new line are stripped. Trailing spaces are not stripped. 
 (assuming that '\n' is the systems line separator)Examples input wrapLength result null * null "" * "" "Here is one line of text that is going to be wrapped after 20 columns." 20 "Here is one line of\ntext that is going\nto be wrapped after\n20 columns." "Click here to jump to the commons website - http://commons.apache.org" 20 "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apache.org" "Click here, http://commons.apache.org, to jump to the commons website" 20 "Click here,\nhttp://commons.apache.org,\nto jump to the\ncommons website" - Parameters:
- str- the String to be word wrapped, may be null
- wrapLength- the column to wrap the words at, less than 1 is treated as 1
- Returns:
- a line with newlines inserted, nullif null input
- See Also:
- Source
 
 - 
wrappublic static java.lang.String wrap(java.lang.String str, int wrapLength, java.lang.String newLineStr, boolean wrapLongWords)Wraps a single line of text, identifying words by ' '.Leading spaces on a new line are stripped. Trailing spaces are not stripped. Examples input wrapLength newLineString wrapLongWords result null * * true/false null "" * * true/false "" "Here is one line of text that is going to be wrapped after 20 columns." 20 "\n" true/false "Here is one line of\ntext that is going\nto be wrapped after\n20 columns." "Here is one line of text that is going to be wrapped after 20 columns." 20 "<br />" true/false "Here is one line of<br />text that is going< br />to be wrapped after<br />20 columns." "Here is one line of text that is going to be wrapped after 20 columns." 20 null true/false "Here is one line of" + systemNewLine + "text that is going" + systemNewLine + "to be wrapped after" + systemNewLine + "20 columns." "Click here to jump to the commons website - http://commons.apache.org" 20 "\n" false "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apache.org" "Click here to jump to the commons website - http://commons.apache.org" 20 "\n" true "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apach\ne.org" - Parameters:
- str- the String to be word wrapped, may be null
- wrapLength- the column to wrap the words at, less than 1 is treated as 1
- newLineStr- the string to insert for a new line,- nulluses the system property line separator
- wrapLongWords- true if long words (such as URLs) should be wrapped
- Returns:
- a line with newlines inserted, nullif null input
- See Also:
- Source
 
 - 
wrappublic static java.lang.String wrap(java.lang.String str, int wrapLength, java.lang.String newLineStr, boolean wrapLongWords, java.lang.String wrapOn)Wraps a single line of text, identifying words by wrapOn.Leading spaces on a new line are stripped. Trailing spaces are not stripped. Examples input wrapLength newLineString wrapLongWords wrapOn result null * * true/false * null "" * * true/false * "" "Here is one line of text that is going to be wrapped after 20 columns." 20 "\n" true/false " " "Here is one line of\ntext that is going\nto be wrapped after\n20 columns." "Here is one line of text that is going to be wrapped after 20 columns." 20 "<br />" true/false " " "Here is one line of<br />text that is going<br /> to be wrapped after<br />20 columns." "Here is one line of text that is going to be wrapped after 20 columns." 20 null true/false " " "Here is one line of" + systemNewLine + "text that is going" + systemNewLine + "to be wrapped after" + systemNewLine + "20 columns." "Click here to jump to the commons website - http://commons.apache.org" 20 "\n" false " " "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apache.org" "Click here to jump to the commons website - http://commons.apache.org" 20 "\n" true " " "Click here to jump\nto the commons\nwebsite -\nhttp://commons.apach\ne.org" "flammable/inflammable" 20 "\n" true "/" "flammable\ninflammable" - Parameters:
- str- the String to be word wrapped, may be null
- wrapLength- the column to wrap the words at, less than 1 is treated as 1
- newLineStr- the string to insert for a new line,- nulluses the system property line separator
- wrapLongWords- true if long words (such as URLs) should be wrapped
- wrapOn- regex expression to be used as a breakable characters, if blank string is provided a space character will be used
- Returns:
- a line with newlines inserted, nullif null input
- See Also:
- Source
 
 - 
escapeJavaStringpublic static java.lang.String escapeJavaString(java.lang.Object object, java.lang.String indent)
 - 
levenshteinDistancepublic static int levenshteinDistance(java.lang.CharSequence left, java.lang.CharSequence right, int threshold)Find the Levenshtein distance between two CharSequences if it's less than or equal to a given threshold.This code is a copy of the limitedComparemethod from Apache commons-text LevenshteinDistance.java.This implementation follows from Algorithms on Strings, Trees and Sequences by Dan Gusfield and Chas Emerick's implementation of the Levenshtein distance algorithm from http://www.merriampark.com/ld.htm limitedCompare(null, *, *) = IllegalArgumentException limitedCompare(*, null, *) = IllegalArgumentException limitedCompare(*, *, -1) = IllegalArgumentException limitedCompare("","", 0) = 0 limitedCompare("aaapppp", "", 8) = 7 limitedCompare("aaapppp", "", 7) = 7 limitedCompare("aaapppp", "", 6)) = -1 limitedCompare("elephant", "hippo", 7) = 7 limitedCompare("elephant", "hippo", 6) = -1 limitedCompare("hippo", "elephant", 7) = 7 limitedCompare("hippo", "elephant", 6) = -1- Parameters:
- left- the first CharSequence, must not be null
- right- the second CharSequence, must not be null
- threshold- the target threshold, must not be negative
- Returns:
- result distance, or -1
- See Also:
- LevenshteinDistance.java
 
 - 
indentpublic static java.lang.String indent(java.lang.String string, int spaces)Indents each line in the provided string by the provided number of spaces.- Parameters:
- string- the string to indent.
- spaces- the number of spaces.
- Returns:
- the indented string.
 
 
- 
 
-