Class StringUtils


  • public final class StringUtils
    extends Object
    • Constructor Detail

      • StringUtils

        public StringUtils()
    • Method Detail

      • trimChar

        public static String trimChar​(String s,
                                      char c)
      • trimOrPad

        public static String trimOrPad​(String str,
                                       int length)
        Trims or pads (with spaces) this string, so it has this exact length.
        Parameters:
        str - The string to adjust. null is treated as an empty string.
        length - The exact length to reach.
        Returns:
        The adjusted string.
      • trimOrPad

        public static String trimOrPad​(String str,
                                       int length,
                                       char padChar)
        Trims or pads this string, so it has this exact length.
        Parameters:
        str - The string to adjust. null is treated as an empty string.
        length - The exact length to reach.
        padChar - The padding character.
        Returns:
        The adjusted string.
      • replaceAll

        public static String replaceAll​(String str,
                                        String originalToken,
                                        String replacementToken)
        Replaces all occurrences of this originalToken in this string with this replacementToken.
        Parameters:
        str - The string to process.
        originalToken - The token to replace.
        replacementToken - The replacement.
        Returns:
        The transformed str.
      • hasLength

        public static boolean hasLength​(String str)
        Checks whether this string is not null and not empty.
        Parameters:
        str - The string to check.
        Returns:
        true if it has content, false if it is null or blank.
      • hasText

        public static boolean hasText​(String s)
        Checks whether this string isn't null and contains at least one non-blank character.
        Parameters:
        s - The string to check.
        Returns:
        true if it has text, false if not.
      • tokenizeToStringArray

        public static String[] tokenizeToStringArray​(String str,
                                                     String delimiters)
        Splits this string into an array using these delimiters.
        Parameters:
        str - The string to split.
        delimiters - The delimiters to use.
        Returns:
        The resulting array.
      • tokenizeToStringCollection

        public static List<String> tokenizeToStringCollection​(String str,
                                                              String delimiters)
        Splits this string into a collection using these delimiters.
        Parameters:
        str - The string to split.
        delimiters - The delimiters to use.
        Returns:
        The resulting array.
      • startsAndEndsWith

        public static boolean startsAndEndsWith​(String str,
                                                String prefix,
                                                Collection<String> suffixes)
        Checks whether str both begins with this prefix and ends withs either of these suffixes.
        Parameters:
        str - The string to check.
        prefix - The prefix.
        suffixes - The suffixes.
        Returns:
        true if it does, false if not.