Class StringUtils

java.lang.Object
no.mnemonic.commons.utilities.StringUtils

public class StringUtils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Tests if a string is blank (null, "" or only whitespace).
    static boolean
    Tests if a string is empty (null or "").
    static boolean
    Simple method to test if an input string can be parsed to an integer.
    static boolean
    Simple method to test if an input string can be parsed to an UUID by UUID.fromString().
    static int
    Null-safe operation to determine the length of a string.

    Methods inherited from class java.lang.Object

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

    • isEmpty

      public static boolean isEmpty(String str)
      Tests if a string is empty (null or "").
      Parameters:
      str - String to be tested.
      Returns:
      Returns true if a string is null or "".
    • isBlank

      public static boolean isBlank(String str)
      Tests if a string is blank (null, "" or only whitespace).
      Parameters:
      str - String to be tested.
      Returns:
      Returns true if a string is null, "" or only contains whitespace.
    • length

      public static int length(String str)
      Null-safe operation to determine the length of a string.
      Parameters:
      str - String to compute length for.
      Returns:
      Returns 0 if 'str' is null, otherwise the length of 'str'.
    • isInteger

      public static boolean isInteger(String str)
      Simple method to test if an input string can be parsed to an integer. The input can be negative (with a minus sign immediately prefixing the numbers). No number separators or spaces will be accepted. The method will return true even if the integer string is too large to be represented by a Java Integer or Long. If the method returns true, the input string should be parseable with Integer.parseInt or Long.parseLong with the exception of integer overflow.
      Parameters:
      str - string to test
      Returns:
      true if string can be parsed to a integer number
    • isUUID

      public static boolean isUUID(String str)
      Simple method to test if an input string can be parsed to an UUID by UUID.fromString(). The method will only check the expected format of hexadecimal characters and hyphens, it does not check if the UUID is valid according to UUID version rules. If the method returns true, the input string should be parseable with UUID.fromString()
      Parameters:
      str - string to test
      Returns:
      true if string can be parsed to a UUID
      See Also: