This class tries to handle null input gracefully. An exception will not be thrown for a
null input. Each method documents its behavior in more detail.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static String | Returns: The abbreviated String.
WordUtils.abbreviate("Now is the time for all good men", 0, 40, null)); = "Now"
WordUtils.abbreviate("Now is the time for all good men", 10, 40, null)); = "Now is the"
WordUtils.abbreviate("Now is the time for all good men", 20, 40, null)); = "Now is the time for all"
WordUtils.abbreviate("Now is the time for all good men", 0, 40, "")); = "Now"
WordUtils.abbreviate("Now is the time for all good men", 10, 40, "")); = "Now is the"
WordUtils.abbreviate("Now is the time for all good men", 20, 40, "")); = "Now is the time for all"
WordUtils.abbreviate("Now is the time for all good men", 0, 40, " ...")); = "Now ..."
WordUtils.abbreviate("Now is the time for all good men", 10, 40, " ...")); = "Now is the ..."
WordUtils.abbreviate("Now is the time for all good men", 20, 40, " ...")); = "Now is the time for all ..."
WordUtils.abbreviate("Now is the time for all good men", 0, -1, "")); = "Now"
WordUtils.abbreviate("Now is the time for all good men", 10, -1, "")); = "Now is the"
WordUtils.abbreviate("Now is the time for all good men", 20, -1, "")); = "Now is the time for all"
WordUtils.abbreviate("Now is the time for all good men", 50, -1, "")); = "Now is the time for all good men"
WordUtils.abbreviate("Now is the time for all good men", 1000, -1, "")); = "Now is the time for all good men"
WordUtils.abbreviate("Now is the time for all good men", 9, -10, null)); = Throws the string to be abbreviated. If null is passed, null is returned.
If the empty String is passed, the empty string is returned. str, int the lower limit; negative value is treated as zero. lower, int the upper limit; specify -1 if no limit is desired.
The upper limit cannot be lower than the lower limit. upper, final String String to be appended to the end of the abbreviated string.
This is appended ONLY if the string was indeed abbreviated.
The append does not count towards the lower or upper limits. appendToEnd)Abbreviates the words nicely. |
| public static String | Returns: capitalized String,null if null String input.the String to capitalize, may be null. str)Capitalizes all the whitespace separated words in a String. |
| public static String | Returns: capitalized String,null if null String input.the String to capitalize, may be null. str, final char... set of characters to determine capitalization, null means whitespace. delimiters)Capitalizes all the delimiter separated words in a String. |
| public static String | Returns: capitalized String,null if null String input.the String to capitalize, may be null. str)Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters. |
| public static String | Returns: capitalized String,null if null String input.the String to capitalize, may be null. str, final char... set of characters to determine capitalization, null means whitespace. delimiters)Converts all the delimiter separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters. |
| public static boolean | Returns: true if all search words are found, false otherwise.The CharSequence to check, may be null. word, final CharSequence... The array of String words to search for, may be null. words)Checks if the String contains all words in the given array. |
| private static Predicate | Returns: Predicateset of characters to determine delimiters, null means whitespace. delimiters)Given the array of delimiters supplied; returns a function determining whether a character code point is a delimiter. |
| public static String | |
| public static String | |
| public static boolean | Returns: true if it is a delimiter.the character to check. ch, final char[] the delimiters. delimiters)
Deprecated
as of 1.2 and will be removed in 2.0.
Is the character a delimiter. |
| public static boolean | Returns: true if it is a delimiter.the codePint to check. codePoint, final char[] the delimiters. delimiters)
Deprecated
as of 1.2 and will be removed in 2.0.
Is the codePoint a delimiter. |
| public static String | |
| public static String | Returns: uncapitalized String,null if null String input.the String to uncapitalize, may be null. str)Uncapitalizes all the whitespace separated words in a String. |
| public static String | Returns: uncapitalized String,null if null String input.the String to uncapitalize, may be null. str, final char... set of characters to determine uncapitalization, null means whitespace. delimiters)Uncapitalizes all the whitespace separated words in a String. |
| public static String | |
| public static String | Returns: a line with newlines inserted,null if null input.the String to be word wrapped, may be null. str, final int the column to wrap the words at, less than 1 is treated as 1. wrapLength, final String the string to insert for a new line, newLineStr, final boolean null uses the system property line separator.true if long words (such as URLs) should be wrapped. wrapLongWords)Wraps a single line of text, identifying words by |
| public static String | Returns: a line with newlines inserted,null if null input.the String to be word wrapped, may be null. str, int the column to wrap the words at, less than 1 is treated as 1. wrapLength, String the string to insert for a new line, newLineStr, final boolean null uses the system property line separator.true if long words (such as URLs) should be wrapped. wrapLongWords, String regex expression to be used as a breakable characters, if blank string is provided a space character will be used. wrapOn)Wraps a single line of text, identifying words by |
| WordUtils | back to summary |
|---|---|
| public WordUtils()
This constructor is public to permit tools that require a JavaBean instance to operate. | |
| abbreviate | back to summary |
|---|---|
| public static String abbreviate(final String str, int lower, int upper, final String appendToEnd) Abbreviates the words nicely. This method searches for the first space after the lower limit and abbreviates the String there. It will also append any String passed as a parameter to the end of the String. The upper limit can be specified to forcibly abbreviate a String.
| |
| capitalize | back to summary |
|---|---|
| public static String capitalize(final String str) Capitalizes all the whitespace separated words in a String.
Only the first character of each word is changed. To convert the
rest of each word to lowercase at the same time,
use Whitespace is defined by
WordUtils.capitalize(null) = null
WordUtils.capitalize("") = ""
WordUtils.capitalize("i am FINE") = "I Am FINE"
| |
| capitalize | back to summary |
|---|---|
| public static String capitalize(final String str, final char... delimiters) Capitalizes all the delimiter separated words in a String.
Only the first character of each word is changed. To convert the
rest of each word to lowercase at the same time,
use The delimiters represent a set of characters understood to separate words. The first string character and the first non-delimiter character after a delimiter will be capitalized. A
WordUtils.capitalize(null, *) = null
WordUtils.capitalize("", *) = ""
WordUtils.capitalize(*, new char[0]) = *
WordUtils.capitalize("i am fine", null) = "I Am Fine"
WordUtils.capitalize("i aM.fine", {'.'}) = "I aM.Fine"
WordUtils.capitalize("i am fine", new char[]{}) = "I am fine"
| |
| capitalizeFully | back to summary |
|---|---|
| public static String capitalizeFully(final String str) Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters. Whitespace is defined by
WordUtils.capitalizeFully(null) = null
WordUtils.capitalizeFully("") = ""
WordUtils.capitalizeFully("i am FINE") = "I Am Fine"
| |
| capitalizeFully | back to summary |
|---|---|
| public static String capitalizeFully(String str, final char... delimiters) Converts all the delimiter separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters. The delimiters represent a set of characters understood to separate words. The first string character and the first non-delimiter character after a delimiter will be capitalized. A
WordUtils.capitalizeFully(null, *) = null
WordUtils.capitalizeFully("", *) = ""
WordUtils.capitalizeFully(*, null) = *
WordUtils.capitalizeFully(*, new char[0]) = *
WordUtils.capitalizeFully("i aM.fine", {'.'}) = "I am.Fine"
| |
| containsAllWords | back to summary |
|---|---|
| public static boolean containsAllWords(final CharSequence word, final CharSequence... words) Checks if the String contains all words in the given array.
A
WordUtils.containsAllWords(null, *) = false
WordUtils.containsAllWords("", *) = false
WordUtils.containsAllWords(*, null) = false
WordUtils.containsAllWords(*, []) = false
WordUtils.containsAllWords("abcd", "ab", "cd") = false
WordUtils.containsAllWords("abc def", "def", "abc") = true
| |
| generateIsDelimiterFunction | back to summary |
|---|---|
| private static Predicate Given the array of delimiters supplied; returns a function determining whether a character code point is a delimiter.
The function provides O(1) lookup time.
Whitespace is defined by | |
| initials | back to summary |
|---|---|
| public static String initials(final String str) Extracts the initial characters from each word in the String. All first characters after whitespace are returned as a new string. Their case is not changed. Whitespace is defined by
WordUtils.initials(null) = null
WordUtils.initials("") = ""
WordUtils.initials("Ben John Lee") = "BJL"
WordUtils.initials("Ben J.Lee") = "BJ"
| |
| initials | back to summary |
|---|---|
| public static String initials(final String str, final char... delimiters) Extracts the initial characters from each word in the String. All first characters after the defined delimiters are returned as a new string. Their case is not changed. If the delimiters array is null, then Whitespace is used.
Whitespace is defined by
WordUtils.initials(null, *) = null
WordUtils.initials("", *) = ""
WordUtils.initials("Ben John Lee", null) = "BJL"
WordUtils.initials("Ben J.Lee", null) = "BJ"
WordUtils.initials("Ben J.Lee", [' ','.']) = "BJL"
WordUtils.initials(*, new char[0]) = ""
| |
| isDelimiter | back to summary |
|---|---|
| public static boolean isDelimiter(final char ch, final char[] delimiters)
Deprecated as of 1.2 and will be removed in 2.0. Is the character a delimiter.
| |
| isDelimiter | back to summary |
|---|---|
| public static boolean isDelimiter(final int codePoint, final char[] delimiters)
Deprecated as of 1.2 and will be removed in 2.0. Is the codePoint a delimiter.
| |
| swapCase | back to summary |
|---|---|
| public static String swapCase(final String str) Swaps the case of a String using a word based algorithm.
Whitespace is defined by
StringUtils.swapCase(null) = null
StringUtils.swapCase("") = ""
StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
| |
| uncapitalize | back to summary |
|---|---|
| public static String uncapitalize(final String str) Uncapitalizes all the whitespace separated words in a String. Only the first character of each word is changed. Whitespace is defined by
WordUtils.uncapitalize(null) = null
WordUtils.uncapitalize("") = ""
WordUtils.uncapitalize("I Am FINE") = "i am fINE"
| |
| uncapitalize | back to summary |
|---|---|
| public static String uncapitalize(final String str, final char... delimiters) Uncapitalizes all the whitespace separated words in a String. Only the first character of each word is changed. The delimiters represent a set of characters understood to separate words. The first string character and the first non-delimiter character after a delimiter will be uncapitalized. Whitespace is defined by
WordUtils.uncapitalize(null, *) = null
WordUtils.uncapitalize("", *) = ""
WordUtils.uncapitalize(*, null) = *
WordUtils.uncapitalize(*, new char[0]) = *
WordUtils.uncapitalize("I AM.FINE", {'.'}) = "i AM.fINE"
WordUtils.uncapitalize("I am fine", new char[]{}) = "i am fine"
| |
| wrap | back to summary | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public static String wrap(final String str, final 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.
| |||||||||||||||||||
| wrap | back to summary | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public static String wrap(final String str, final int wrapLength, final String newLineStr, final boolean wrapLongWords) Wraps a single line of text, identifying words by Leading spaces on a new line are stripped. Trailing spaces are not stripped.
| |||||||||||||||||||||||||||||||||||||||||
| wrap | back to summary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public static String wrap(final String str, int wrapLength, String newLineStr, final boolean wrapLongWords, String wrapOn) Wraps a single line of text, identifying words by Leading spaces on a new line are stripped. Trailing spaces are not stripped.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||