Stringutils provides the following features and Methods. All methods are null secure and thread secure:
- Isempty/isblank-Checks if a string contains text
Blank detection. Empty refers to a blank string, that is, the length is 0; Blank refers to a blank string, the length is not necessarily set to 0, may contain blank characters or tabs.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false
- Trim/Strip-Removes leading and trailing whitespace
- Equals-Compares two strings null-safe
- Startswith-Check if a string starts with a prefix null-safe
- Endswith-Check if a string ends with a suffix null-safe
- Indexof/lastindexof/contains-Null-safe index-of checks
- Indexofany/lastindexofany/indexofanybut/lastindexofanybut-Index-of any of a set of strings
- Containsonly/containsnone/containsany-Does string contains only/NONE/any of these characters
- Substring/left/right/Mid-Null-safe substring extractions
- Substringbefore/substringafter/substringbetween-Substring extraction relative to other strings
- Split/join-Splits a string into an array of substrings and vice versa
- Remove/delete-Removes part of a string
- Replace/overlay-Searches a string and replaces one string with another
- Chomp/chop-Removes the last part of a string
- Leftpad/rightpad/center/repeat-Pads a string
- Uppercase/lowercase/swapcase/capitalize/uncapitalize-Changes the case of a string
- Countmatches-Counts the number of occurrences of one string in another
- Isalpha/isnumeric/iswhitespace/isasciiprintable-Checks the characters in a string
- Defaultstring-Protects against a null input string
- Reverse/reversedelimited-Reverses a string
- Abbreviate-Abbreviates a string using ellipsis
- Difference-Compares strings and reports on their differences
- Levenshteindistance-The number of changes needed to change one string into another
Word Meaning:
- Null-
null
- Empty-A zero-length string (
""
)
- Space-The space character (
' '
, Char 32)
- Whitespace-The characters defined
Character.isWhitespace(char)
- Trim-The characters <= 32 as in
String.trim()