Class StringUtil

java.lang.Object
com.github.toolarium.common.util.StringUtil

public final class StringUtil extends Object
String util class
  • Method Details

    • getInstance

      public static StringUtil getInstance()
      Get the instance
      Returns:
      the instance
    • newStringBuilder

      public StringBuilder newStringBuilder(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 StringBuilder newStringBuilder(char character, int num)
      New string builder with given length and filled up with the given character
      Parameters:
      character - character to fill up the string
      num - the number of repetitions
      Returns:
      a filled up string
    • newString

      public String newString(CharSequence input, int num)
      New string builder
      Parameters:
      input - the input string to repeat
      num - the number of repetitions
      Returns:
      the prepared string
    • newString

      public String newString(char character, int num)
      New string with given length and filled up with the given character
      Parameters:
      character - character to fill up the string
      num - the number of repetitions
      Returns:
      a filled up string
    • width

      public String width(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 String 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:
         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(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(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 String trimRight(String data)
      Trims a given string from the right side.
      Parameters:
      data - the string to format
      Returns:
      the trimed string
    • trimRight

      public String trimRight(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 String trimLeft(String data)
      Trims a given string from the left side.
      Parameters:
      data - the string to format
      Returns:
      the trimed string
    • trimLeft

      public String trimLeft(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 String toString(String[] array)
      Converts the given string array to a string
      Parameters:
      array - the data to parse
      Returns:
      the converted string
    • toString

      public String toString(String[] array, 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 String toString(Object[] array)
      Converts the given string array to a string
      Parameters:
      array - the data to parse
      Returns:
      the converted string
    • toString

      public String toString(Object[] array, String sep)
      Converts the given array to a string
      Parameters:
      array - the data to parse
      sep - the separator
      Returns:
      the converted string
    • toString

      public String toString(byte[] b)
      Converts a given byte array to a string representation
      Parameters:
      b - the bytes
      Returns:
      bytes as string
    • toString

      public 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 List<String> splitAsList(String splitString, int partLength)
      Split a string into a list by length
      Parameters:
      splitString - the string to split
      partLength - the length into which the input string is to be divided
      Returns:
      the string list or null
    • splitAsList

      public List<String> splitAsList(String expression, String splitString)
      Split a string into a list
      Parameters:
      expression - the expression to split
      splitString - the string, whereby the expression string is split
      Returns:
      the string list or null
    • splitAsArray

      public String[] splitAsArray(String splitString, int partLength)
      Split a string into an array by length
      Parameters:
      splitString - the string to split
      partLength - the length into which the input string is to be divided
      Returns:
      the array or null
    • splitAsArray

      public String[] splitAsArray(String expression, String splitString)
      Split a string into an array
      Parameters:
      expression - the expression to split
      splitString - the string, whereby the expression string is split
      Returns:
      the array or null
    • changeFirstLetterToUpperCase

      public String changeFirstLetterToUpperCase(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 String changeFirstLetterToLowerCase(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 String toCamelCase(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
    • fromCamelCaseToSnakeCase

      public String fromCamelCaseToSnakeCase(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 format
      toLowerCase - true to lower snake case; otherwise to upper snake case
      Returns:
      the formated string
    • toSnakeCase

      public String toSnakeCase(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