Package com.github.toolarium.common.util
Class StringUtil
java.lang.Object
com.github.toolarium.common.util.StringUtil
String util class
-
Method Summary
Modifier and TypeMethodDescriptionChanges the first letter of the given String to a lower case letter.Changes the first letter of the given String to an upper case letter.intcountCharacters(String input, char ch) Counts a given character in the given String.intcountEndingCharacter(String input, char ch) Count of a string a given ending character how many times it is existingfromCamelCaseToSnakeCase(String data, boolean toLowerCase) Convert a given string from CamelCase notation to upper case formated string.static StringUtilGet the instancenewString(char character, int num) New string with given length and filled up with the given characternewString(CharSequence input, int num) New string buildernewStringBuilder(char character, int num) New string builder with given length and filled up with the given characternewStringBuilder(CharSequence input, int num) New string builderString[]splitAsArray(String splitString, int partLength) Split a string into an array by lengthString[]splitAsArray(String expression, String splitString) Split a string into an arraysplitAsList(String splitString, int partLength) Split a string into a list by lengthsplitAsList(String expression, String splitString) Split a string into a listtoCamelCase(String data, boolean startWithLowerCase) Convert a given string to CamelCase formated string (lower/upper or pascal case).toSnakeCase(String data) Convert a given string to SnakeCase formated string.toString(byte[] b) Converts a given byte array to a string representationtoString(byte[] b, int ofs, int len) Converts a given byte array to a string representationConverts the given string array to a stringConverts the given array to a stringConverts the given string array to a stringConverts the given string array to a stringTrims a given string from the left side.Trims a given string from the left side.Trims a given string from the right side.Trims a given string from the right side.width(CharSequence text, int width) Format a given string to a given length and fill up with the given character Example:width(CharSequence text, int width, char fillupChar, boolean cutRight) Format a given string to a given length and fill up with the given character Example:
-
Method Details
-
getInstance
Get the instance- Returns:
- the instance
-
newStringBuilder
New string builder- Parameters:
input- the input string to repeatnum- the number of repetitions- Returns:
- the prepared string
-
newStringBuilder
New string builder with given length and filled up with the given character- Parameters:
character- character to fill up the stringnum- the number of repetitions- Returns:
- a filled up string
-
newString
New string builder- Parameters:
input- the input string to repeatnum- the number of repetitions- Returns:
- the prepared string
-
newString
New string with given length and filled up with the given character- Parameters:
character- character to fill up the stringnum- the number of repetitions- Returns:
- a filled up string
-
width
Format a given string to a given length and fill up with the given character Example:input: text: "fobar" width: 8 fillupChar: '-' cutRight: false output: fobar---- Parameters:
text- the string to testwidth- the width of the string- Returns:
- the formated string
-
width
Format a given string to a given length and fill up with the given character Example:input: text: "fobar" width: 8 fillupChar: '-' cutRight: false output: fobar---- Parameters:
text- the string to testwidth- the width of the stringfillupChar- character to fill up the stringcutRight- if the given string is too long then cut it on the right side- Returns:
- the formated string
-
countCharacters
Counts a given character in the given String.- Parameters:
input- the string to count the characters.ch- the character to count.- Returns:
- the number of occurrences of the given character in the given string
-
countEndingCharacter
Count of a string a given ending character how many times it is existing- Parameters:
input- the input stringch- the character to test- Returns:
- the number of found ch characters at the end
-
trimRight
Trims a given string from the right side.- Parameters:
data- the string to format- Returns:
- the trimed string
-
trimRight
Trims a given string from the right side.- Parameters:
data- the string to formatch- the character to trim from the string- Returns:
- the trimed string
-
trimLeft
Trims a given string from the left side.- Parameters:
data- the string to format- Returns:
- the trimed string
-
trimLeft
Trims a given string from the left side.- Parameters:
data- the string to formatch- the character to trim from the string- Returns:
- the trimed string
-
toString
Converts the given string array to a string- Parameters:
array- the data to parse- Returns:
- the converted string
-
toString
Converts the given string array to a string- Parameters:
array- the data to parsesep- the separator- Returns:
- the converted string
-
toString
Converts the given string array to a string- Parameters:
array- the data to parse- Returns:
- the converted string
-
toString
Converts the given array to a string- Parameters:
array- the data to parsesep- the separator- Returns:
- the converted string
-
toString
Converts a given byte array to a string representation- Parameters:
b- the bytes- Returns:
- bytes as string
-
toString
Converts a given byte array to a string representation- Parameters:
b- the bytesofs- the offsetlen- the length of the bytes- Returns:
- bytes as string
-
splitAsList
Split a string into a list by length- Parameters:
splitString- the string to splitpartLength- the length into which the input string is to be divided- Returns:
- the string list or null
-
splitAsList
Split a string into a list- Parameters:
expression- the expression to splitsplitString- the string, whereby the expression string is split- Returns:
- the string list or null
-
splitAsArray
Split a string into an array by length- Parameters:
splitString- the string to splitpartLength- the length into which the input string is to be divided- Returns:
- the array or null
-
splitAsArray
Split a string into an array- Parameters:
expression- the expression to splitsplitString- the string, whereby the expression string is split- Returns:
- the array or null
-
changeFirstLetterToUpperCase
Changes the first letter of the given String to an upper case letter.- Parameters:
name- A name.- Returns:
- The first letter of the given String to an upper case letter.
-
changeFirstLetterToLowerCase
Changes the first letter of the given String to a lower case letter.- Parameters:
name- A name.- Returns:
- The first letter of the given String to a lower case letter.
-
toCamelCase
Convert a given string to CamelCase formated string (lower/upper or pascal case). Example:- input: This is an example
- output: ThisIsAnExample
- Parameters:
data- the string to formatstartWithLowerCase- true to start with lower case (lower camel case); otherwise false (upper camel or pascal case)- Returns:
- the formated string
-
fromCamelCaseToSnakeCase
Convert a given string from CamelCase notation to upper case formated string. Example: input: ThisIsAnExample output: THIS_IS_AN_EXAMPLE- Parameters:
data- the string to formattoLowerCase- true to lower snake case; otherwise to upper snake case- Returns:
- the formated string
-
toSnakeCase
Convert a given string to SnakeCase formated string. Example: input: This is an example output: This_is_an_example- Parameters:
data- the string to format- Returns:
- the formated string
-