Class StringUtils


  • public final class StringUtils
    extends Object
    Miscellaneous string comparison utility methods.
    • Method Detail

      • toLowerCase

        public static char toLowerCase​(char c)
        Convert the input to lowercase.

        This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale. Only characters in the range 'A' through 'Z' are converted. All other characters are left as-is, even if they otherwise would have a lowercase character equivalent.

        Parameters:
        c - the input character.
        Returns:
        lowercase version of the input.
      • toLowerCase

        public static String toLowerCase​(String in)
        Convert the input string to lower case, according to the "C" locale.

        This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale. Only characters in the range 'A' through 'Z' are converted, all other characters are left as-is, even if they otherwise would have a lowercase character equivalent.

        Parameters:
        in - the input string. Must not be null.
        Returns:
        a copy of the input string, after converting characters in the range 'A'..'Z' to 'a'..'z'.
      • equalsIgnoreCase

        public static boolean equalsIgnoreCase​(String a,
                                               String b)
        Test if two strings are equal, ignoring case.

        This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.

        Parameters:
        a - first string to compare.
        b - second string to compare.
        Returns:
        true if a equals b
      • compareIgnoreCase

        public static int compareIgnoreCase​(String a,
                                            String b)
        Compare two strings, ignoring case.

        This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.

        Parameters:
        a - first string to compare.
        b - second string to compare.
        Returns:
        negative, zero or positive if a sorts before, is equal to, or sorts after b.
        Since:
        2.0
      • compareWithCase

        public static int compareWithCase​(String a,
                                          String b)
        Compare two strings, honoring case.

        This method does not honor the JVM locale, but instead always behaves as though it is in the US-ASCII locale.

        Parameters:
        a - first string to compare.
        b - second string to compare.
        Returns:
        negative, zero or positive if a sorts before, is equal to, or sorts after b.
        Since:
        2.0
      • toBoolean

        public static boolean toBoolean​(String stringValue)
        Parse a string as a standard Git boolean value. See toBooleanOrNull(String).
        Parameters:
        stringValue - the string to parse.
        Returns:
        the boolean interpretation of value.
        Throws:
        IllegalArgumentException - if value is not recognized as one of the standard boolean names.
      • toBooleanOrNull

        public static Boolean toBooleanOrNull​(String stringValue)
        Parse a string as a standard Git boolean value.

        The terms yes, true, 1, on can all be used to mean true.

        The terms no, false, 0, off can all be used to mean false.

        Comparisons ignore case, via equalsIgnoreCase(String, String).

        Parameters:
        stringValue - the string to parse.
        Returns:
        the boolean interpretation of value or null in case the string does not represent a boolean value
      • join

        public static String join​(Collection<String> parts,
                                  String separator)
        Join a collection of Strings together using the specified separator.
        Parameters:
        parts - Strings to join
        separator - used to join
        Returns:
        a String with all the joined parts
      • join

        public static String join​(Collection<String> parts,
                                  String separator,
                                  String lastSeparator)
        Join a collection of Strings together using the specified separator and a lastSeparator which is used for joining the second last and the last part.
        Parameters:
        parts - Strings to join
        separator - separator used to join all but the two last elements
        lastSeparator - separator to use for joining the last two elements
        Returns:
        a String with all the joined parts
      • isEmptyOrNull

        public static boolean isEmptyOrNull​(String stringValue)
        Test if a string is empty or null.
        Parameters:
        stringValue - the string to check
        Returns:
        true if the string is null or empty
      • replaceLineBreaksWithSpace

        public static String replaceLineBreaksWithSpace​(String in)
        Replace CRLF, CR or LF with a single space.
        Parameters:
        in - A string with line breaks
        Returns:
        in without line breaks
        Since:
        3.1