Class StringUtils


  • public final class StringUtils
    extends java.lang.Object
    Fast string utilities.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<java.lang.String> split​(java.lang.String str, char sep)
      Splits a String around each occurence of the specified character.
      static void split​(java.lang.String str, char sep, java.util.List<java.lang.String> list)
      Splits a String around each occurence of the specified character, and puts the result in the given List.
      static java.util.List<java.lang.String> splitLines​(java.lang.String str)
      Splits a String around each occurence of LF and CRLF.
      static void splitLines​(java.lang.String str, java.util.List<java.lang.String> list)
      Splits a String around each occurence of LF and CRLF, and puts the result in the given 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 str,
                                                             char sep)
        Splits a String around each occurence of the specified character. The result is not the same as String.split(String). In particular, this method never returns an empty list.

        Examples:

        • split("a.b.c", '.') gives ["a", "b", "c"]
        • split("", '.') gives [""] (a list containing the empty string)
        • split(".", '.') gives ["", ""] (a list containing two empty strings)
        • split("..", '.') gives ["", "", ""] (a list containing three empty strings)
        • split(".a...b.", '.') gives ["", "a", "", "", "b", ""] (a list containing an empty string, the string "a", two empty strings, the string "b", and an empty string)
        Parameters:
        str - the String to split
        sep - the separator to use
        Returns:
        a non-empty list of strings
      • split

        public static void split​(java.lang.String str,
                                 char sep,
                                 java.util.List<java.lang.String> list)
        Splits a String around each occurence of the specified character, and puts the result in the given List. The result is not the same as String.split(String). In particular, this method always add at least one element to the list.

        Examples:

        • split("a.b.c", '.') gives ["a", "b", "c"]
        • split("", '.') gives [""] (a list containing the empty string)
        • split(".", '.') gives ["", ""] (a list containing two empty strings)
        • split("..", '.') gives ["", "", ""] (a list containing three empty strings)
        • split(".a...b.", '.') gives ["", "a", "", "", "b", ""] (a list containing an empty string, the string "a", two empty strings, the string "b", and an empty string)
        Parameters:
        str - the String to split
        sep - the separator to use
        list - the list where to put the results
      • splitLines

        public static java.util.List<java.lang.String> splitLines​(java.lang.String str)
        Splits a String around each occurence of LF and CRLF. If the String is null or empty, then an empty list is returned.
        Parameters:
        str - the String to split
        Returns:
        a list of strings, may be empty
      • splitLines

        public static void splitLines​(java.lang.String str,
                                      java.util.List<java.lang.String> list)
        Splits a String around each occurence of LF and CRLF, and puts the result in the given list.
        Parameters:
        str - the String to split
        list - the list where to put the result