Class StringUtil


  • public class StringUtil
    extends java.lang.Object
    Utility class for common application string functions.
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] fromHex​(java.lang.String hexString)
      Creates byte array from a hex represented string.
      static java.lang.String getStackTrace​(java.lang.Exception exception)  
      static <T> java.lang.String join​(java.util.List<T> objects, java.lang.String delimiter)  
      static <T> java.lang.String join​(java.util.List<T> objects, java.lang.String delimiter, StringUtil.StringJoinListener<T> listener)  
      static <T> java.lang.String join​(T[] objects, java.lang.String delimiter)  
      static <T> java.lang.String join​(T[] objects, java.lang.String delimiter, StringUtil.StringJoinListener<T> listener)  
      static int substrCount​(java.lang.String haystack, java.lang.String needle)
      Returns the count of the substring
      static byte[] toBytesUTF8​(java.lang.String s)
      Creates a byte array from a given string, using the UTF-8 encoding.
      static java.lang.String toCamelCase​(java.lang.String str)
      Transforms a string to a camel case representation, including the first character.
      static java.lang.String toHex​(byte[] bytes)
      Converts a byte array to a lower case hex representation.
      static java.lang.String toSnakeCase​(java.lang.String str)
      Transforms a string to underscore-delimited representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toCamelCase

        public static java.lang.String toCamelCase​(java.lang.String str)
        Transforms a string to a camel case representation, including the first character.

        Examples:

        • toCamelCase("hello world") -> "HelloWorld"
        • toCamelCase("hello_world") -> "HelloWorld"
        • toCamelCase("hello_World") -> "HelloWorld"
        • toCamelCase("helloWorld") -> "HelloWorld"
        • toCamelCase("HelloWorld") -> "HelloWorld"
      • toSnakeCase

        public static java.lang.String toSnakeCase​(java.lang.String str)
        Transforms a string to underscore-delimited representation.

        Examples:

        • toUnderScoreDelimited("HelloWorld") -> "hello_world"
        • toUnderScoreDelimited("helloWorld") -> "hello_world"
      • toHex

        public static java.lang.String toHex​(byte[] bytes)
        Converts a byte array to a lower case hex representation. If the given byte array is null, an empty string is returned.
      • fromHex

        public static byte[] fromHex​(java.lang.String hexString)
        Creates byte array from a hex represented string.
      • toBytesUTF8

        public static byte[] toBytesUTF8​(java.lang.String s)
        Creates a byte array from a given string, using the UTF-8 encoding. This calls String.getBytes(java.nio.charset.Charset) internally with "UTF-8" as charset.
      • substrCount

        public static int substrCount​(java.lang.String haystack,
                                      java.lang.String needle)
        Returns the count of the substring
      • getStackTrace

        public static java.lang.String getStackTrace​(java.lang.Exception exception)
      • join

        public static <T> java.lang.String join​(java.util.List<T> objects,
                                                java.lang.String delimiter)
      • join

        public static <T> java.lang.String join​(T[] objects,
                                                java.lang.String delimiter)