Class Strings


  • public class Strings
    extends Object
    • Constructor Detail

      • Strings

        public Strings()
    • Method Detail

      • isBlank

        public static boolean isBlank​(String s)
      • isNotBlank

        public static boolean isNotBlank​(String s)
      • isEmpty

        public static boolean isEmpty​(String s)

        Returns whether the specified string is empty while remaining null-safe.

        Parameters:
        s - the string to be checked (may be null)
        Returns:
        true if s is either null or contains no characters.
      • isNotEmpty

        public static boolean isNotEmpty​(String s)

        Returns whether the specified string is not empty while remaining null-safe.

        Parameters:
        s - the string to be checked (may be null)
        Returns:
        true if s is not null and contains at least one character.
      • trim

        public static String trim​(String s)

        Trims the specified string while remaining null-safe.

        Parameters:
        s - the string to be trimmed (may be null)
        Returns:
        The trimmed s or null if s is null.
      • trimToNull

        public static String trimToNull​(String s)

        Trims the specified string and, if the resulting string is empty, will return null instead.

        Parameters:
        s - the string to be trimmed (may be null)
        Returns:
        The trimmed s or null if s is null before or after being trimmed.
      • joinClassNames

        public static String joinClassNames​(Iterable<?> iterable)
      • toBoolean

        public static Boolean toBoolean​(String s)

        Attempts to return the best boolean representation for the specified string while remaining null-safe and ignoring any leading/trailing whitespace as well as case.

        This method simply uses a set of predefined values that it compares s to in order to determine the best Boolean representation. If s does not fall into either category, it is considered invalid and will result in an IllegalArgumentException being thrown.

        Parameters:
        s - the string to be converted into a Boolean
        Returns:
        The Boolean representation of s or null if s is null.
        Throws:
        IllegalArgumentException - If s is non-null and does not match any of the predefined values.