Class Strings


  • public final class Strings
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.CharSequence clean​(java.lang.CharSequence str)  
      static java.lang.String clean​(java.lang.String str)  
      static boolean hasLength​(java.lang.CharSequence str)
      Check that the given CharSequence is neither null nor of length 0.
      static boolean hasText​(java.lang.CharSequence str)
      Check whether the given CharSequence has actual text.
      static boolean hasText​(java.lang.String str)
      Check whether the given String has actual text.
      static java.lang.String trimWhitespace​(java.lang.String str)
      Trim leading and trailing whitespace from the given String.
      • Methods inherited from class java.lang.Object

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

      • hasLength

        public static boolean hasLength​(java.lang.CharSequence str)
        Check that the given CharSequence is neither null nor of length 0. Note: Will return true for a CharSequence that purely consists of whitespace.

         Strings.hasLength(null) = false
         Strings.hasLength("") = false
         Strings.hasLength(" ") = true
         Strings.hasLength("Hello") = true
         
        Parameters:
        str - the CharSequence to check (may be null)
        Returns:
        true if the CharSequence is not null and has length
        See Also:
        hasText(String)
      • hasText

        public static boolean hasText​(java.lang.CharSequence str)
        Check whether the given CharSequence has actual text. More specifically, returns true if the string not null, its length is greater than 0, and it contains at least one non-whitespace character.

         Strings.hasText(null) = false
         Strings.hasText("") = false
         Strings.hasText(" ") = false
         Strings.hasText("12345") = true
         Strings.hasText(" 12345 ") = true
         
        Parameters:
        str - the CharSequence to check (may be null)
        Returns:
        true if the CharSequence is not null, its length is greater than 0, and it does not contain whitespace only
        See Also:
        Character.isWhitespace(char)
      • hasText

        public static boolean hasText​(java.lang.String str)
        Check whether the given String has actual text. More specifically, returns true if the string not null, its length is greater than 0, and it contains at least one non-whitespace character.
        Parameters:
        str - the String to check (may be null)
        Returns:
        true if the String is not null, its length is greater than 0, and it does not contain whitespace only
        See Also:
        hasText(CharSequence)
      • trimWhitespace

        public static java.lang.String trimWhitespace​(java.lang.String str)
        Trim leading and trailing whitespace from the given String.
        Parameters:
        str - the String to check
        Returns:
        the trimmed String
        See Also:
        Character.isWhitespace(char)
      • clean

        public static java.lang.String clean​(java.lang.String str)
      • clean

        public static java.lang.CharSequence clean​(java.lang.CharSequence str)