StringUtils

By | April 5, 2020

StringUtils class is provided by Apache. Standard libraries present in Java doesn’t provide all the methods required for manipulation so Apache Commons Lang provides these extra methods.

Below are the methods provided in StringUtils class and these are all null safe.

Equals/Compare: It compares whether two given strings are equal or not.
EqualsAny: Compares if the first string is equal to the given searchStrings.
IsEmpty/IsBlank: checks if a String contains text
Trim/Strip: removes leading and trailing whitespace from string.
startsWith: check if a String starts with a prefix / specified characters
endsWith: check if a String ends with a suffix / specified characters.
UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize: Used to change the case of a String
IndexOf/LastIndexOf/Contains: checks the index of string
IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut: Checks the index of given Strings
ContainsOnly/ContainsNone/ContainsAny: does String contains only/none/any of these characters
IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable: checks the characters in a String

Reverse/ReverseDelimited: It reverses a String
Substring/Left/Right/Mid: It extracts substrings
SubstringBefore/SubstringAfter/SubstringBetween: substring extraction relative to other strings
Split/Join: Splits a String into an array of substrings and vice versa
Remove/Delete: It removes part of a String
Replace/Overlay: Searches a String and replaces one String with another
AppendIfMissing: Used to append a suffix to the end of the String if not present
PrependIfMissing: Used to prepend a prefix to the start of the String if not present
LeftPad/RightPad/Center/Repeat: It adds padding to a String

CountMatches: counts the number of occurrences of one String in another
DefaultString: protects against a null input String
Rotate: It rotates (circular shift) a String
Difference: compares Strings and reports on their differences
LevenshteinDistance: the number of changes needed to change one String into another
Chomp/Chop: Used to remove the last part of a String
Abbreviate: abbreviates a string using ellipsis or another given String

 

Source: http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html

Leave a Reply

Your email address will not be published. Required fields are marked *