Class StringUtil


  • public final class StringUtil
    extends Object
    The StringUtil is a utility class for working with Strings.

    Includes some methods with signatures similar to those exposed by .NET's String class.

    • Method Detail

      • isNullOrEmpty

        public static boolean isNullOrEmpty​(String input)

        Determines whether a string is null or empty.

        Parameters:
        input - a String object.
        Returns:
        a boolean.
      • getNullIfEmpty

        public static String getNullIfEmpty​(String input)

        Returns null if the input String is empty. Otherwise the String.

        Parameters:
        input - a String object.
        Returns:
        a String object.
      • getEmptyIfNull

        public static String getEmptyIfNull​(String input)

        Returns the empty string if the input String is null. Otherwise the String.

        Parameters:
        input - a String object.
        Returns:
        a String object.
      • repeatChar

        public static String repeatChar​(char character,
                                        int count)

        Returns a string that contains the specified character count times.

        Parameters:
        character - a char.
        count - a int.
        Returns:
        a String object.
      • padRight

        public static String padRight​(String input,
                                      int totalWidth)

        Appends spaces to a String.

        Parameters:
        input - a String object.
        totalWidth - a int.
        Returns:
        a String object.
      • padLeft

        public static String padLeft​(String input,
                                     int totalWidth)

        Prepends spaces to a String.

        Parameters:
        input - a String object.
        totalWidth - a int.
        Returns:
        a String object.
      • compare

        public static int compare​(String str1,
                                  String str2,
                                  boolean ignoreCase)

        Compares two Strings.

         StringUtil.compare(null, null) = 0
         StringUtil.compare(null, "...") = -1
         StringUtil.compare("...", null) = 1
         
        Parameters:
        str1 - a String object.
        str2 - a String object.
        ignoreCase - a boolean.
        Returns:
        a int.
      • join

        public static String join​(String separator,
                                  String[] value)

        Joins the elements of a String[] using the specified separator.

        Parameters:
        separator - a String object.
        value - an array of String objects.
        Returns:
        a String object.