Class StringUtil


  • public final class StringUtil
    extends java.lang.Object
    String util class
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String changeFirstLetterToLowerCase​(java.lang.String name)
      Changes the first letter of the given String to a lower case letter.
      java.lang.String changeFirstLetterToUpperCase​(java.lang.String name)
      Changes the first letter of the given String to an upper case letter.
      int countCharacters​(java.lang.String input, char ch)
      Counts a given character in the given String.
      int countEndingCharacter​(java.lang.String input, char ch)
      Count of a string a given ending character how many times it is existing
      java.lang.String fromCamelCaseToSnakeCase​(java.lang.String data, boolean toLowerCase)
      Convert a given string from CamelCase notation to upper case formated string.
      static StringUtil getInstance()
      Get the instance
      java.lang.String newString​(char character, int num)
      New string with given length and filled up with the given character
      java.lang.String newString​(java.lang.CharSequence input, int num)
      New string builder
      java.lang.StringBuilder newStringBuilder​(char character, int num)
      New string builder with given length and filled up with the given character
      java.lang.StringBuilder newStringBuilder​(java.lang.CharSequence input, int num)
      New string builder
      java.lang.String[] splitAsArray​(java.lang.String expression, java.lang.String splitString)
      Split a string into an array
      java.util.List<java.lang.String> splitAsList​(java.lang.String expression, java.lang.String splitString)
      Split a string into a list
      java.lang.String toCamelCase​(java.lang.String data, boolean startWithLowerCase)
      Convert a given string to CamelCase formated string (lower/upper or pascal case).
      java.lang.String toSnakeCase​(java.lang.String data)
      Convert a given string to SnakeCase formated string.
      java.lang.String toString​(byte[] b)
      Converts a given byte array to a string representation
      java.lang.String toString​(byte[] b, int ofs, int len)
      Converts a given byte array to a string representation
      java.lang.String toString​(java.lang.Object[] array)
      Converts the given string array to a string
      java.lang.String toString​(java.lang.Object[] array, java.lang.String sep)
      Converts the given array to a string
      java.lang.String toString​(java.lang.String[] array)
      Converts the given string array to a string
      java.lang.String toString​(java.lang.String[] array, java.lang.String sep)
      Converts the given string array to a string
      java.lang.String trimLeft​(java.lang.String data)
      Trims a given string from the left side.
      java.lang.String trimLeft​(java.lang.String data, char ch)
      Trims a given string from the left side.
      java.lang.String trimRight​(java.lang.String data)
      Trims a given string from the right side.
      java.lang.String trimRight​(java.lang.String data, char ch)
      Trims a given string from the right side.
      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:
      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:
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 repeat
        num - 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 repetitions
        character - 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 repetitions
        input - 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 repetitions
        character - 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 test
        width - 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 test
        width - the width of the string
        fillupChar - character to fill up the string
        cutRight - 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 string
        ch - 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 format
        ch - 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 format
        ch - 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 parse
        sep - 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 parse
        sep - 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 bytes
        ofs - the offset
        len - 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 split
        splitString - 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 split
        splitString - 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 format
startWithLowerCase - true to start with lower case (lower camel case); otherwise false (upper camel or pascal case)
Returns:
the formated string