Class StringUtil

java.lang.Object
org.seppiko.commons.utils.StringUtil

public class StringUtil
extends java.lang.Object
String Util
Author:
Leonard Woo
  • Constructor Summary

    Constructors
    Constructor Description
    StringUtil()  
  • Method Summary

    Modifier and Type Method Description
    static byte[] decodeHex​(char[] data)
    convert hex char array to byte array
    static char[] encodeHex​(byte[] data)
    convert byte array to hex char array
    static char[] encodeHex​(byte[] data, boolean toLowerCase)
    convert byte array to hex char array
    static java.lang.String encodeHexToString​(byte[] data)
    convert byte array to string object
    static char[] encodeHexWithInteger​(byte[] data)
    convert byte array to hex char array
    static java.lang.String fixedLength​(java.lang.String str, int length, char preChar)
    return fixed length string object
    static boolean hasLength​(java.lang.String str)
    test string has any char
    static boolean hasText​(java.lang.CharSequence str)
    test char sequence has any char without whitespace
    static boolean hasText​(java.lang.String str)
    test string has any char without whitespace
    static java.lang.String initialsUpperCase​(java.lang.String str)
    capitalize the first letter
    static boolean isEmpty​(java.lang.String str)
    test string is null or length is 0
    static java.lang.String replaceIndex​(java.lang.CharSequence data, int start, int end, java.lang.CharSequence replacement)
    replace CharSequence between start and end
    static java.lang.String safeNull​(java.lang.String src, java.lang.String defaultValue)
    Get a string object with default value
    static java.lang.String transcoding​(java.lang.String data, java.nio.charset.Charset oldEncoding, java.nio.charset.Charset newEncoding)
    convert string data from old encoding to new encoding

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • safeNull

      public static java.lang.String safeNull​(java.lang.String src, java.lang.String defaultValue)
      Get a string object with default value
      Parameters:
      src - string object
      defaultValue - default string object
      Returns:
      result
    • isEmpty

      public static boolean isEmpty​(java.lang.String str)
      test string is null or length is 0
      Parameters:
      str - string object
      Returns:
      true is yes
    • hasLength

      public static boolean hasLength​(java.lang.String str)
      test string has any char
      Parameters:
      str - string object
      Returns:
      true is yes
    • hasText

      public static boolean hasText​(java.lang.CharSequence str)
      test char sequence has any char without whitespace
      Parameters:
      str - char sequence object
      Returns:
      true is yes
    • hasText

      public static boolean hasText​(java.lang.String str)
      test string has any char without whitespace
      Parameters:
      str - string object
      Returns:
      true is yes
    • transcoding

      public static java.lang.String transcoding​(java.lang.String data, java.nio.charset.Charset oldEncoding, java.nio.charset.Charset newEncoding)
      convert string data from old encoding to new encoding
      Parameters:
      data - string data
      oldEncoding - old encoding
      newEncoding - new encoding
      Returns:
      convert result
    • fixedLength

      public static java.lang.String fixedLength​(java.lang.String str, int length, char preChar)
      return fixed length string object
      Parameters:
      str - string object
      length - length
      preChar - pre-padded character
      Returns:
      fixed length string object
    • initialsUpperCase

      public static java.lang.String initialsUpperCase​(java.lang.String str)
      capitalize the first letter
      Parameters:
      str - origin string
      Returns:
      new string
    • replaceIndex

      public static java.lang.String replaceIndex​(java.lang.CharSequence data, int start, int end, java.lang.CharSequence replacement)
      replace CharSequence between start and end
      Parameters:
      data - origin data
      start - replace start index
      end - replace end index
      replacement - replace data
      Returns:
      new data string
    • encodeHexWithInteger

      public static char[] encodeHexWithInteger​(byte[] data)
      convert byte array to hex char array
      Parameters:
      data - byte array data
      Returns:
      hex char array
    • encodeHexToString

      public static java.lang.String encodeHexToString​(byte[] data)
      convert byte array to string object
      Parameters:
      data - byte array data
      Returns:
      string object
    • encodeHex

      public static char[] encodeHex​(byte[] data)
      convert byte array to hex char array
      Parameters:
      data - byte array data
      Returns:
      hex char array
    • encodeHex

      public static char[] encodeHex​(byte[] data, boolean toLowerCase)
      convert byte array to hex char array
      Parameters:
      data - byte array data
      toLowerCase - true is lower case, false is upper case
      Returns:
      hex char array
    • decodeHex

      public static byte[] decodeHex​(char[] data)
      convert hex char array to byte array
      Parameters:
      data - hex char array
      Returns:
      byte array