Class StringUtils

java.lang.Object
io.github.amanzat.util.StringUtils

public final class StringUtils extends Object
Miscellaneous String utility methods and constants.
  • Field Details

  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • isEmpty

      public static boolean isEmpty(CharSequence charSequence)
      Returns true if the CharSequence is null or empty, false otherwise.
      Parameters:
      charSequence - The CharSequence
      Returns:
      true if the CharSequence is null or empty, false otherwise.
    • length

      public static int length(CharSequence charSequence)
      Returns the length of the CharSequence or 0 if the value is null.
      Parameters:
      charSequence - The CharSequence
      Returns:
      The length of the CharSequence or 0 if the value is null.
    • isBlank

      public static boolean isBlank(CharSequence charSequence)
      Checks if a CharSequence is empty, null or whitespace only.
      Whitespace is defined by Character.isWhitespace(char).
      Parameters:
      charSequence - The CharSequence, may be null
      Returns:
      true if the CharSequence is null, empty or whitespace only, false otherwise.
    • toUpperCase

      public static String toUpperCase(String value)
      Safely converts the specified value to upper-case handling nulls.
      Parameters:
      value - The string value
      Returns:
      The string to uppercase or null.
    • toLowerCase

      public static String toLowerCase(String value)
      Safely converts the specified value to lower-case handling nulls.
      Parameters:
      value - The string value
      Returns:
      The string to lowercase or null.
    • truncateWithMarker

      public static String truncateWithMarker(String value, int maxLength)
      Truncates the specified String value to the maximum length and add the truncation marker if the max length is greater than the marker's length.
      If the string length is less or equal with the maximum length, no truncation is performed.
      Parameters:
      value - The String value to truncate
      maxLength - The maximum length
      Returns:
      The truncated value or the original String.
    • leftPad

      public static String leftPad(String input, int size, char character)
      Left pads the specified string input with the given character.
      Parameters:
      input - The String input to pad
      size - The size to pad
      character - The character to pad with
      Returns:
      The left padded String result.
    • rightPad

      public static String rightPad(String input, int size, char character)
      Right pads the specified string input with the given character.
      Parameters:
      input - The String input to pad
      size - The size to pad
      character - The character to pad with
      Returns:
      The right padded String result.
    • concat

      public static String concat(String value, char delimiter, String... others)
      Concatenates a string with an array of strings using a delimiter and returns the resulting string.
      Parameters:
      value - The string value
      delimiter - The delimiter
      others - The other strings
      Returns:
      The resulting string.
    • concat

      public static String concat(char delimiter, String... values)
      Concatenates an array of strings using a delimiter and returns the resulting string.
      Parameters:
      delimiter - The delimiter
      values - The array of strings
      Returns:
      The resulting string.
    • concat

      public static String[] concat(String value, String... others)
      Concatenates a string with an array of strings and returns the resulting array.
      Parameters:
      value - The string value
      others - The other strings
      Returns:
      The resulting array of strings.
    • onlyDigits

      public static boolean onlyDigits(CharSequence value, int length)
      Checks if the specified CharSequence has only digits and the specified length.
      Parameters:
      value - The CharSequence
      length - The expected length
      Returns:
      true if the value has the expected length and has only digits, false otherwise.