Class StringUtils


  • public final class StringUtils
    extends java.lang.Object
    Some utilities for String.

    Can be used from GWT code.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String abbreviate​(java.lang.String value, int maxLength)  
      static java.lang.String capitalize​(java.lang.String word)  
      static java.lang.String defaultIfBlank​(java.lang.String str, java.lang.String defaultStr)
      Returns defaultStr, if str is blank, or otherwise it returns str itself.
      static java.lang.String emptyIfNull​(java.lang.String stringOrNull)
      Returns an empty string if given stringOrNull is null, otherwise it returns stringOrNull itself.
      static java.lang.String escape​(java.lang.String text, char... escapedChars)
      Escapes escapedChars characters in specified text.
      static boolean isBlank​(java.lang.Object value)
      Whether given value is blank or not.
      static boolean isBlank​(java.lang.String value)
      Whether given value is blank or not.
      static boolean isNotBlank​(java.lang.String value)
      Whether given value is not blank.
      static java.lang.String join​(java.lang.Object[] array, java.lang.String separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static java.lang.String joinList​(java.util.List<java.lang.String> list)
      Joins the elements using comma as a separator.
      static java.lang.String joinList​(java.util.List<java.lang.String> list, java.lang.String separator)
      Joins the elements using comma as a separator.
      static boolean matches​(java.lang.String regExp, java.lang.String value)
      Returns true if given regExp could be found in given value.
      static boolean matches​(java.lang.String regExp, java.lang.String value, java.lang.String modifiers)
      Returns true if given regExp could be found in given value.
      static java.lang.String nullIfBlank​(java.lang.String value)
      Returns null if given value is blank.
      static java.util.List<java.lang.String> tokenize​(java.lang.String str)
      Returns the tokens found in str, where tokens are separated by white spaces.
      static java.lang.String toStringEmptyIfNull​(java.lang.Object objectOrNull)
      Returns an empty string if given objectOrNull is null, otherwise it returns result of Object.toString() on the object.
      static java.lang.String toStringOrNull​(java.lang.Object objectOrNull)
      Returns null if given objectOrNull is null, otherwise it returns result of Object.toString() on the object.
      static java.lang.String trimToNull​(java.lang.String value)
      Trims given value to null.
      • Methods inherited from class java.lang.Object

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

      • EMPTY_STRING_ARRAY

        public static final java.lang.String[] EMPTY_STRING_ARRAY
    • Method Detail

      • isBlank

        public static final boolean isBlank​(java.lang.String value)
        Whether given value is blank or not.
      • isBlank

        public static final boolean isBlank​(java.lang.Object value)
        Whether given value is blank or not.
      • isNotBlank

        public static final boolean isNotBlank​(java.lang.String value)
        Whether given value is not blank.
      • joinList

        public static final java.lang.String joinList​(java.util.List<java.lang.String> list)
        Joins the elements using comma as a separator.
        Example: "a", "b", "c" -> "a, b, c"
      • joinList

        public static final java.lang.String joinList​(java.util.List<java.lang.String> list,
                                                      java.lang.String separator)
        Joins the elements using comma as a separator.
        Example: "a", "b", "c" -> "a, b, c"
      • join

        public static final java.lang.String join​(java.lang.Object[] array,
                                                  java.lang.String separator)
        Joins the elements of the provided array into a single String containing the provided list of elements.
      • capitalize

        public static final java.lang.String capitalize​(java.lang.String word)
      • abbreviate

        public static final java.lang.String abbreviate​(java.lang.String value,
                                                        int maxLength)
      • trimToNull

        public static final java.lang.String trimToNull​(java.lang.String value)
        Trims given value to null.
        Returns:
        null if given value is blank.
      • nullIfBlank

        public static final java.lang.String nullIfBlank​(java.lang.String value)
        Returns null if given value is blank.
      • emptyIfNull

        public static final java.lang.String emptyIfNull​(java.lang.String stringOrNull)
        Returns an empty string if given stringOrNull is null, otherwise it returns stringOrNull itself.
      • toStringEmptyIfNull

        public static final java.lang.String toStringEmptyIfNull​(java.lang.Object objectOrNull)
        Returns an empty string if given objectOrNull is null, otherwise it returns result of Object.toString() on the object.
      • toStringOrNull

        public static final java.lang.String toStringOrNull​(java.lang.Object objectOrNull)
        Returns null if given objectOrNull is null, otherwise it returns result of Object.toString() on the object.
      • defaultIfBlank

        public static final java.lang.String defaultIfBlank​(java.lang.String str,
                                                            java.lang.String defaultStr)
        Returns defaultStr, if str is blank, or otherwise it returns str itself.
      • escape

        public static final java.lang.String escape​(java.lang.String text,
                                                    char... escapedChars)
        Escapes escapedChars characters in specified text.
      • tokenize

        public static final java.util.List<java.lang.String> tokenize​(java.lang.String str)
        Returns the tokens found in str, where tokens are separated by white spaces.
      • matches

        public static final boolean matches​(java.lang.String regExp,
                                            java.lang.String value,
                                            java.lang.String modifiers)
        Returns true if given regExp could be found in given value.

        Allowed modifiers are:

        • i - Perform case-insensitive matching
        • g - Perform a global match (find all matches rather than stopping after the first match)
        • m - Perform multiline matching
      • matches

        public static final boolean matches​(java.lang.String regExp,
                                            java.lang.String value)
        Returns true if given regExp could be found in given value.