Package io.github.amanzat.util
Class StringUtils
java.lang.Object
io.github.amanzat.util.StringUtils
Miscellaneous
String utility methods and constants.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringConcatenates an array of strings using a delimiter and returns the resulting string.static StringConcatenates a string with an array of strings using a delimiter and returns the resulting string.static String[]Concatenates a string with an array of strings and returns the resulting array.static booleanisBlank(CharSequence charSequence) Checks if a CharSequence is empty,nullor whitespace only.static booleanisEmpty(CharSequence charSequence) static StringLeft pads the specified string input with the given character.static intlength(CharSequence charSequence) Returns the length of theCharSequenceor 0 if the value isnull.static booleanonlyDigits(CharSequence value, int length) Checks if the specifiedCharSequencehas only digits and the specified length.static StringRight pads the specified string input with the given character.static StringtoLowerCase(String value) Safely converts the specifiedvalueto lower-case handlingnulls.static StringtoUpperCase(String value) Safely converts the specifiedvalueto upper-case handlingnulls.static StringtruncateWithMarker(String value, int maxLength) Truncates the specifiedStringvalue to the maximum length and add the truncation marker if the max length is greater than the marker's length.
-
Field Details
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
isEmpty
- Parameters:
charSequence- TheCharSequence- Returns:
trueif theCharSequenceisnullor empty,falseotherwise.
-
length
Returns the length of theCharSequenceor 0 if the value isnull.- Parameters:
charSequence- TheCharSequence- Returns:
- The length of the
CharSequenceor 0 if the value isnull.
-
isBlank
Checks if a CharSequence is empty,nullor whitespace only.
Whitespace is defined byCharacter.isWhitespace(char).- Parameters:
charSequence- TheCharSequence, may benull- Returns:
trueif the CharSequence isnull, empty or whitespace only,falseotherwise.
-
toUpperCase
Safely converts the specifiedvalueto upper-case handlingnulls.- Parameters:
value- The string value- Returns:
- The string to uppercase or
null.
-
toLowerCase
Safely converts the specifiedvalueto lower-case handlingnulls.- Parameters:
value- The string value- Returns:
- The string to lowercase or
null.
-
truncateWithMarker
Truncates the specifiedStringvalue to the maximum length and add the truncation marker if the max length is greater than the marker's length.
If the string length is less or equal with the maximum length, no truncation is performed. -
leftPad
Left pads the specified string input with the given character.- Parameters:
input- TheStringinput to padsize- The size to padcharacter- The character to pad with- Returns:
- The left padded String result.
-
rightPad
Right pads the specified string input with the given character.- Parameters:
input- TheStringinput to padsize- The size to padcharacter- The character to pad with- Returns:
- The right padded String result.
-
concat
Concatenates a string with an array of strings using a delimiter and returns the resulting string.- Parameters:
value- The string valuedelimiter- The delimiterothers- The other strings- Returns:
- The resulting string.
-
concat
Concatenates an array of strings using a delimiter and returns the resulting string.- Parameters:
delimiter- The delimitervalues- The array of strings- Returns:
- The resulting string.
-
concat
Concatenates a string with an array of strings and returns the resulting array.- Parameters:
value- The string valueothers- The other strings- Returns:
- The resulting array of strings.
-
onlyDigits
Checks if the specifiedCharSequencehas only digits and the specified length.- Parameters:
value- TheCharSequencelength- The expected length- Returns:
trueif the value has the expected length and has only digits,falseotherwise.
-