Class Strings


  • public final class Strings
    extends Object
    Collection of string helper methods.
    • Method Detail

      • abbreviate

        public static String abbreviate​(String str,
                                        int offset,
                                        int maxWidth)
      • abbreviateMiddle

        public static String abbreviateMiddle​(String string,
                                              int maxLength)
      • abbreviateFqClassName

        public static String abbreviateFqClassName​(String fqcn)
      • capitalize

        public static String capitalize​(String str)
      • substringAfterLast

        public static String substringAfterLast​(String str,
                                                String separator)
      • strip

        public static String strip​(String str,
                                   String stripChars)

        Strips any of a set of characters from the start and end of a String. This is similar to String.trim() but allows the characters to be stripped to be controlled.

        A null input String returns null. An empty string ("") input returns the empty string.

         StringUtils.strip(null, *)          = null
         StringUtils.strip("", *)            = ""
         StringUtils.strip("abc", null)      = "abc"
         StringUtils.strip("  abc", null)    = "abc"
         StringUtils.strip("abc  ", null)    = "abc"
         StringUtils.strip(" abc ", null)    = "abc"
         StringUtils.strip("  abcyx", "xyz") = "  abc"
         
        Parameters:
        str - the String to remove characters from, may be null
        stripChars - the characters to remove, null treated as whitespace
        Returns:
        the stripped String, null if null String input
      • stripStart

        public static String stripStart​(String str,
                                        String stripChars)

        Strips any of a set of characters from the start of a String.

        A null input String returns null. An empty string ("") input returns the empty string.

        If the stripChars String is null, whitespace is stripped as defined by Character.isWhitespace(char).

         StringUtils.stripStart(null, *)          = null
         StringUtils.stripStart("", *)            = ""
         StringUtils.stripStart("abc", "")        = "abc"
         StringUtils.stripStart("abc", null)      = "abc"
         StringUtils.stripStart("  abc", null)    = "abc"
         StringUtils.stripStart("abc  ", null)    = "abc  "
         StringUtils.stripStart(" abc ", null)    = "abc "
         StringUtils.stripStart("yxabc  ", "xyz") = "abc  "
         
        Parameters:
        str - the String to remove characters from, may be null
        stripChars - the characters to remove, null treated as whitespace
        Returns:
        the stripped String, null if null String input
      • stripEnd

        public static String stripEnd​(String str,
                                      String stripChars)

        Strips any of a set of characters from the end of a String.

        A null input String returns null. An empty string ("") input returns the empty string.

        If the stripChars String is null, whitespace is stripped as defined by Character.isWhitespace(char).

         StringUtils.stripEnd(null, *)          = null
         StringUtils.stripEnd("", *)            = ""
         StringUtils.stripEnd("abc", "")        = "abc"
         StringUtils.stripEnd("abc", null)      = "abc"
         StringUtils.stripEnd("  abc", null)    = "  abc"
         StringUtils.stripEnd("abc  ", null)    = "abc"
         StringUtils.stripEnd(" abc ", null)    = " abc"
         StringUtils.stripEnd("  abcyx", "xyz") = "  abc"
         StringUtils.stripEnd("120.00", ".0")   = "12"
         
        Parameters:
        str - the String to remove characters from, may be null
        stripChars - the set of characters to remove, null treated as whitespace
        Returns:
        the stripped String, null if null String input
      • getParent

        public static String getParent​(String path)
      • getDomain

        public static String getDomain​(String url)