Class StringUtils


  • public final class StringUtils
    extends 

    Utility methods for String objects.

    This class is used as a basis for the methods offered by Strings, which in turn are the methods offered by the #strings utility object in variable expressions.

    Since:
    1.0
    Author:
    Daniel Fernández, Le Roux Bernard, Soraya Sánchez Labandeira
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static  target, int maxSize)  
      static  target,  suffix)  
      static  target)
      Convert the first letter of target to uppercase (title-case, in fact).
      static  target)
      Convert all the first letter of the words of target to uppercase (title-case, in fact).
      static  target,  delimiters)
      Convert all the first letter of the words of target to uppercase (title-case, in fact), using the specified delimiter chars for determining word ends/starts.
      static ... values)  
      static  nullValue, ... values)  
      static  target,  fragment)  
      static  target,  fragment,  locale)  
      static  target,  suffix)  
      static  first,  second)  
      static  first,  second)  
      static  target)
      Escapes the specified target text as required for Java code.
      static  target)
      Escapes the specified target text as required for JavaScript code.
      static  target)
      XML-escapes the specified text.
      static  target,  fragment)  
      static boolean  target)  
      static boolean  target)  
      static <?> target, char separator)  
      static <?> target,  separator)  
      static [] target,  separator)  
      static  target)  
      static  target)
      Removes all whitespaces and control chars at all positions, and transforms to lower case.
      static  target,  prefix)  
      static randomAlphanumeric​(int count)  
      static  target, int times)  
      static  target,  before,  after)  
      static []  target,  separator)  
      static  target,  prefix)  
      static  target, int beginIndex)
      copy a part of target start beginIndex to the end of target.
      static  target, int beginIndex, int endIndex)  
      static  target,  substr)  
      static  target,  substr)  
      static  target,  locale)  
      static  target)
      Performs a null-safe toString() operation.
      static  target,  locale)  
      static  target)  
      static  target)
      Convert the first letter of target to lowercase.
      static  target)
      Un-escapes the specified Java-escaped target text back to normal form.
      static  target)
      Un-escapes the specified JavaScript-escaped target text back to normal form.
      • Methods inherited from class java.lang.

        , , , , , , , , , ,
    • Method Detail

      • toString

        public static  toString​( target)

        Performs a null-safe toString() operation.

        Parameters:
        target - the object on which toString will be executed
        Returns:
        the result of calling target.toString() if target is not null, null if target is null.
        Since:
        2.0.12
      • abbreviate

        public static  abbreviate​( target,
                                        int maxSize)
      • equals

        public static  equals​( first,
                                      second)
        Parameters:
        first - first
        second - second
        Returns:
        the result
        Since:
        2.0.16
      • equalsIgnoreCase

        public static  equalsIgnoreCase​( first,
                                                second)
        Parameters:
        first - first
        second - second
        Returns:
        the result
        Since:
        2.0.16
      • contains

        public static  contains​( target,
                                        fragment)
      • containsIgnoreCase

        public static  containsIgnoreCase​( target,
                                                  fragment,
                                                  locale)
      • startsWith

        public static  startsWith​( target,
                                          prefix)
      • endsWith

        public static  endsWith​( target,
                                        suffix)
      • substring

        public static  substring​( target,
                                       int beginIndex,
                                       int endIndex)
      • substring

        public static  substring​( target,
                                       int beginIndex)

        copy a part of target start beginIndex to the end of target. If non-String object, toString() will be called.

        Parameters:
        target - source of the copy.
        beginIndex - index where the copy start.
        Returns:
        part of target, or null if target is null.
        Since:
        1.1.2
      • substringAfter

        public static  substringAfter​( target,
                                             substr)
      • substringBefore

        public static  substringBefore​( target,
                                              substr)
      • prepend

        public static  prepend​( target,
                                      prefix)
      • append

        public static  append​( target,
                                     suffix)
      • repeat

        public static  repeat​( target,
                                    int times)
        Parameters:
        target - target
        times - times
        Returns:
        the result
        Since:
        2.1.0
      • concat

        public static  concat​(... values)
        Parameters:
        values - values
        Returns:
        the result
        Since:
        2.0.16
      • concatReplaceNulls

        public static  concatReplaceNulls​( nullValue,
                                                ... values)
        Parameters:
        nullValue - nullValue
        values - values
        Returns:
        the result
        Since:
        2.0.16
      • indexOf

        public static  indexOf​( target,
                                       fragment)
      • isEmpty

        public static boolean isEmpty​( target)
        Parameters:
        target - target
        Returns:
        the result
        Since:
        2.1.0
      • isEmptyOrWhitespace

        public static boolean isEmptyOrWhitespace​( target)
      • join

        public static  join​([] target,
                                   separator)
      • join

        public static  join​(<?> target,
                                   separator)
      • join

        public static  join​(<?> target,
                                  char separator)
      • split

        public static [] split​( target,
                                      separator)
      • length

        public static  length​( target)
      • replace

        public static  replace​( target,
                                      before,
                                      after)
      • toUpperCase

        public static  toUpperCase​( target,
                                          locale)
      • toLowerCase

        public static  toLowerCase​( target,
                                          locale)
      • trim

        public static  trim​( target)
      • pack

        public static  pack​( target)
        Removes all whitespaces and control chars at all positions, and transforms to lower case.
        Parameters:
        target - the string to be packed
        Returns:
        the packed string
        Since:
        3.0.12
      • capitalize

        public static  capitalize​( target)

        Convert the first letter of target to uppercase (title-case, in fact).

        Parameters:
        target - the String to be capitalized. If non-String object, toString() will be called.
        Returns:
        String the result of capitalizing the target.
        Since:
        1.1.2
      • unCapitalize

        public static  unCapitalize​( target)

        Convert the first letter of target to lowercase.

        Parameters:
        target - the String to be uncapitalized. If non-String object, toString() will be called.
        Returns:
        String the result of uncapitalizing the target.
        Since:
        1.1.2
      • capitalizeWords

        public static  capitalizeWords​( target)

        Convert all the first letter of the words of target to uppercase (title-case, in fact). The default delimiter characters between the words are the whitespace characters (see Characters.IsWhiteSpace method in the Java doc).

        Parameters:
        target - the String to be capitalized. If non-String object, toString() will be called.
        Returns:
        String the result of capitalizing the target.
        Since:
        1.1.2
      • capitalizeWords

        public static  capitalizeWords​( target,
                                              delimiters)

        Convert all the first letter of the words of target to uppercase (title-case, in fact), using the specified delimiter chars for determining word ends/starts.

        Parameters:
        target - the String to be capitalized. If non-String object, toString() will be called.
        delimiters - delimiters of the words. If non-String object, toString() will be called.
        Returns:
        String the result of capitalizing the target.
        Since:
        1.1.2
      • escapeXml

        public static  escapeXml​( target)

        XML-escapes the specified text.

        Parameters:
        target - the text to be escaped
        Returns:
        the escaped text.
        Since:
        2.0.9
      • escapeJavaScript

        public static  escapeJavaScript​( target)

        Escapes the specified target text as required for JavaScript code.

        Parameters:
        target - the text to be escaped
        Returns:
        the escaped text.
        Since:
        2.0.11
      • escapeJava

        public static  escapeJava​( target)

        Escapes the specified target text as required for Java code.

        Parameters:
        target - the text to be escaped
        Returns:
        the escaped text.
        Since:
        2.0.11
      • unescapeJavaScript

        public static  unescapeJavaScript​( target)

        Un-escapes the specified JavaScript-escaped target text back to normal form.

        Parameters:
        target - the text to be unescaped
        Returns:
        the unescaped text.
        Since:
        2.0.11
      • unescapeJava

        public static  unescapeJava​( target)

        Un-escapes the specified Java-escaped target text back to normal form.

        Parameters:
        target - the text to be unescaped
        Returns:
        the unescaped text.
        Since:
        2.0.11
      • randomAlphanumeric

        public static  randomAlphanumeric​(int count)