Class StringUtils

java.lang.Object
com.electronwill.nightconfig.core.utils.StringUtils

public final class StringUtils extends Object
Fast string utilities.
  • Method Details

    • split

      public static List<String> split(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(String str, char sep, List<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 List<String> splitLines(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(String str, List<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