Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isBlank​(java.lang.String s)
      Returns true if the string is null or it does not contain any non space characters.
      static boolean isEmpty​(java.lang.String str)
      Checks if a String is empty ("") or null.
      static java.lang.String joinStrings​(java.util.List<java.lang.String> list, java.lang.String delim)
      This method takes a List<String> and a delimiter and joins the strings into a single string, where the original strings are separated using the given delimiter.
      static java.util.List<java.lang.String> split​(java.lang.String value, java.lang.String separator)
      This method returns an immutable List<String>, but different from String's split() it trims the results in the input String, and removes any empty string from the resulting List.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • split

        public static java.util.List<java.lang.String> split​(java.lang.String value,
                                                             java.lang.String separator)
        This method returns an immutable List<String>, but different from String's split() it trims the results in the input String, and removes any empty string from the resulting List.
      • joinStrings

        public static java.lang.String joinStrings​(java.util.List<java.lang.String> list,
                                                   java.lang.String delim)
        This method takes a List<String> and a delimiter and joins the strings into a single string, where the original strings are separated using the given delimiter. This method is a null-safe version of String.join(CharSequence, Iterable)

        Note that if an individual element is null, then "null" is added.

        Parameters:
        list - a List that will have its elements joined together
        delim - a sequence of characters that is used to separate each of the elements in the resulting String
        Returns:
        a new String that is composed from the elements argument or null if list is null
        Throws:
        java.lang.NullPointerException - if delim is null
      • isBlank

        public static boolean isBlank​(java.lang.String s)
        Returns true if the string is null or it does not contain any non space characters.
        Parameters:
        s - the string
        Returns:
        true if the string is null or it does not contain any non space characters.
      • isEmpty

        public static boolean isEmpty​(java.lang.String str)

        Checks if a String is empty ("") or null.

         StringUtils.isEmpty(null)      = true
         StringUtils.isEmpty("")        = true
         StringUtils.isEmpty(" ")       = false
         StringUtils.isEmpty("bob")     = false
         StringUtils.isEmpty("  bob  ") = false
         
        Parameters:
        str - the String to check, may be null
        Returns:
        true if the String is empty or null