Package com.github.toolarium.common.util
Class StringUtil
- java.lang.Object
-
- com.github.toolarium.common.util.StringUtil
-
public final class StringUtil extends java.lang.ObjectString util class
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringchangeFirstLetterToLowerCase(java.lang.String name)Changes the first letter of the given String to a lower case letter.java.lang.StringchangeFirstLetterToUpperCase(java.lang.String name)Changes the first letter of the given String to an upper case letter.intcountCharacters(java.lang.String input, char ch)Counts a given character in the given String.intcountEndingCharacter(java.lang.String input, char ch)Count of a string a given ending character how many times it is existingjava.lang.StringfromCamelCaseToSnakeCase(java.lang.String data, boolean toLowerCase)Convert a given string from CamelCase notation to upper case formated string.static StringUtilgetInstance()Get the instancejava.lang.StringnewString(char character, int num)New string with given length and filled up with the given characterjava.lang.StringnewString(java.lang.CharSequence input, int num)New string builderjava.lang.StringBuildernewStringBuilder(char character, int num)New string builder with given length and filled up with the given characterjava.lang.StringBuildernewStringBuilder(java.lang.CharSequence input, int num)New string builderjava.lang.String[]splitAsArray(java.lang.String expression, java.lang.String splitString)Split a string into an arrayjava.util.List<java.lang.String>splitAsList(java.lang.String expression, java.lang.String splitString)Split a string into a listjava.lang.StringtoCamelCase(java.lang.String data, boolean startWithLowerCase)Convert a given string to CamelCase formated string (lower/upper or pascal case).java.lang.StringtoSnakeCase(java.lang.String data)Convert a given string to SnakeCase formated string.java.lang.StringtoString(byte[] b)Converts a given byte array to a string representationjava.lang.StringtoString(byte[] b, int ofs, int len)Converts a given byte array to a string representationjava.lang.StringtoString(java.lang.Object[] array)Converts the given string array to a stringjava.lang.StringtoString(java.lang.Object[] array, java.lang.String sep)Converts the given array to a stringjava.lang.StringtoString(java.lang.String[] array)Converts the given string array to a stringjava.lang.StringtoString(java.lang.String[] array, java.lang.String sep)Converts the given string array to a stringjava.lang.StringtrimLeft(java.lang.String data)Trims a given string from the left side.java.lang.StringtrimLeft(java.lang.String data, char ch)Trims a given string from the left side.java.lang.StringtrimRight(java.lang.String data)Trims a given string from the right side.java.lang.StringtrimRight(java.lang.String data, char ch)Trims a given string from the right side.java.lang.Stringwidth(java.lang.CharSequence text, int width)Format a given string to a given length and fill up with the given character Example:java.lang.Stringwidth(java.lang.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 Detail
-
getInstance
public static StringUtil getInstance()
Get the instance- Returns:
- the instance
-
newStringBuilder
public java.lang.StringBuilder newStringBuilder(java.lang.CharSequence input, int num)New string builder- Parameters:
input- the input string to repeatnum- the number of repetitions- Returns:
- the prepared string
-
newStringBuilder
public java.lang.StringBuilder newStringBuilder(char character, int num)New string builder with given length and filled up with the given character- Parameters:
num- the number of repetitionscharacter- character to fill up the string- Returns:
- a filled up string
-
newString
public java.lang.String newString(java.lang.CharSequence input, int num)New string builder- Parameters:
num- the number of repetitionsinput- the input string to repeat- Returns:
- the prepared string
-
newString
public java.lang.String newString(char character, int num)New string with given length and filled up with the given character- Parameters:
num- the number of repetitionscharacter- character to fill up the string- Returns:
- a filled up string
-
width
public java.lang.String width(java.lang.CharSequence text, int 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
public java.lang.String width(java.lang.CharSequence text, int width, char fillupChar, boolean cutRight)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
public int countCharacters(java.lang.String input, char ch)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
public int countEndingCharacter(java.lang.String input, char ch)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
public java.lang.String trimRight(java.lang.String data)
Trims a given string from the right side.- Parameters:
data- the string to format- Returns:
- the trimed string
-
trimRight
public java.lang.String trimRight(java.lang.String data, char ch)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
public java.lang.String trimLeft(java.lang.String data)
Trims a given string from the left side.- Parameters:
data- the string to format- Returns:
- the trimed string
-
trimLeft
public java.lang.String trimLeft(java.lang.String data, char ch)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
public java.lang.String toString(java.lang.String[] array)
Converts the given string array to a string- Parameters:
array- the data to parse- Returns:
- the converted string
-
toString
public java.lang.String toString(java.lang.String[] array, java.lang.String sep)Converts the given string array to a string- Parameters:
array- the data to parsesep- the separator- Returns:
- the converted string
-
toString
public java.lang.String toString(java.lang.Object[] array)
Converts the given string array to a string- Parameters:
array- the data to parse- Returns:
- the converted string
-
toString
public java.lang.String toString(java.lang.Object[] array, java.lang.String sep)Converts the given array to a string- Parameters:
array- the data to parsesep- the separator- Returns:
- the converted string
-
toString
public java.lang.String toString(byte[] b)
Converts a given byte array to a string representation- Parameters:
b- the bytes- Returns:
- bytes as string
-
toString
public java.lang.String toString(byte[] b, int ofs, int len)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
public java.util.List<java.lang.String> splitAsList(java.lang.String expression, java.lang.String splitString)Split a string into a list- Parameters:
expression- the expression to splitsplitString- the split string- Returns:
- the string list or null
-
splitAsArray
public java.lang.String[] splitAsArray(java.lang.String expression, java.lang.String splitString)Split a string into an array- Parameters:
expression- the expression to splitsplitString- the split string- Returns:
- the array or null
-
changeFirstLetterToUpperCase
public java.lang.String changeFirstLetterToUpperCase(java.lang.String name)
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
public java.lang.String changeFirstLetterToLowerCase(java.lang.String name)
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
public java.lang.String toCamelCase(java.lang.String data, boolean startWithLowerCase)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
public java.lang.String fromCamelCaseToSnakeCase(java.lang.String data, boolean toLowerCase)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
public java.lang.String toSnakeCase(java.lang.String data)
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
-
-