Class StringUtils


  • public final class StringUtils
    extends Object
    This class provides static helper methods for CharSequence.
    • Constructor Detail

      • StringUtils

        public StringUtils()
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(CharSequence value)
        Check whether the given string value is empty. The value is empty if null or length is 0.
        Parameters:
        value - the string value to test
        Returns:
        true if empty false otherwise
      • notEmpty

        public static boolean notEmpty​(CharSequence value)
        Check whether the given string value is not empty. The value is empty if null or length is 0.
        Parameters:
        value - the string value to test
        Returns:
        true if not empty false otherwise
      • isBlank

        public static boolean isBlank​(CharSequence value)
        Check whether the given string value is blank. The value is blank if null or contains white spaces only.
        Parameters:
        value - the string value to test
        Returns:
        true if empty false otherwise
      • notBlank

        public static boolean notBlank​(CharSequence value)
        Check whether the given string value is not blank. The value is blank if null or contains white spaces only.
        Parameters:
        value - the string value to test
        Returns:
        true if not empty false otherwise
      • stripAccent

        public static String stripAccent​(CharSequence value)
        Remove diacritics (accents) from a CharSequence.
        Parameters:
        value - the string to be stripped
        Returns:
        text with diacritics removed
      • stripIndent

        public static String stripIndent​(CharSequence text)
        Strip the leading indentation from the given text.

        The line with the least number of leading spaces determines the number to remove. Lines only containing whitespace are ignored when calculating the number of leading spaces to strip.

        Parameters:
        text - the text to strip indent from
        Returns:
        stripped text
      • stripMargin

        public static String stripMargin​(CharSequence text)
        Strip leading whitespace/control characters followed by '|' from every line in the given text.
        Parameters:
        text - the text to strip the margin from
        Returns:
        the stripped String
      • isAscii

        public static boolean isAscii​(CharSequence text)
        Returns true if the text is in the ASCII charset.
        Parameters:
        text - the text to check
        Returns:
        true if the text is in the ASCII charset; false otherwise
      • isAscii

        public static boolean isAscii​(char c)
        Returns true if the character is in the ASCII charset.
        Parameters:
        c - the character to check
        Returns:
        true if the character is in the ASCII charset; false otherwise
      • splitToArray

        public static String[] splitToArray​(String text,
                                            String delimiter)
        Split the given text into an array using the given delimiter.

        The result parts are trimmed and empty part omitted.

        Parameters:
        text - the text to slip
        delimiter - the delimiter
        Returns:
        array of string
      • splitToArray

        public static String[] splitToArray​(String text,
                                            String delimiter,
                                            boolean trimResult,
                                            boolean ignoreEmpty)
        Split the given text into an array using the given delimiter.
        Parameters:
        text - the text to slip
        delimiter - the delimiter
        trimResult - whether to trim the result parts
        ignoreEmpty - whether to omit empty part
        Returns:
        array of string