Class StringUtils
- java.lang.Object
-
- com.electronwill.nightconfig.core.utils.StringUtils
-
public final class StringUtils extends java.lang.ObjectFast 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 voidsplit(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 voidsplitLines(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.
-
-
-
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 asString.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 splitsep- 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 asString.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 splitsep- the separator to uselist- 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 splitlist- the list where to put the result
-
-