Class StringUtils


  • public final class StringUtils
    extends Object
    String Utilities
    Author:
    Brian Wyka
    • Method Detail

      • isBlankOrEmpty

        public static boolean isBlankOrEmpty​(String string)
        Determine if a string is blank or empty
        Parameters:
        string - the string to check
        Returns:
        true if null, empty, or blank
      • isNotBlankOrEmpty

        public static boolean isNotBlankOrEmpty​(String string)
        Determine if a string is not blank or empty
        Parameters:
        string - the string to check
        Returns:
        true if NOT null, empty, or blank
      • startsWith

        public static boolean startsWith​(CharSequence subject,
                                         CharSequence prefix)
        Determine if a string starts with the provided prefix
        Parameters:
        subject - the subject to check for prefix
        prefix - the sequence to check for at beginning
        Returns:
        true if starts with prefix, false otherwise
      • equals

        public static boolean equals​(CharSequence charSequenceOne,
                                     CharSequence charSequenceTwo)
        Determine if two character sequences are equal to each other
        Parameters:
        charSequenceOne - character sequence one
        charSequenceTwo - character sequence two
        Returns:
        true if equal, false otherwise
      • removeNewLines

        public static String removeNewLines​(String string)
        Remove new lines and carriage returns
        Parameters:
        string - the string to remove from
        Returns:
        the modified string with new lines and carriage returns removed
      • isUrl

        public static boolean isUrl​(String url)
        Determine whether or not the string provided is a URL
        Parameters:
        url - the string to check
        Returns:
        true if a URL, false otherwise
      • defaultString

        public static String defaultString​(String str,
                                           String defaultStr)

        Returns either the passed in String, or if the String is null, the value of defaultStr.

         StringUtils.defaultString(null, "NULL")  = "NULL"
         StringUtils.defaultString("", "NULL")    = ""
         StringUtils.defaultString("bat", "NULL") = "bat"
         
        Parameters:
        str - the String to check, may be null
        defaultStr - the default String to return if the input is null, may be null
        Returns:
        the passed in String, or the default if it was null
        See Also:
        String.valueOf(Object)