Class StringUtils
java.lang.Object
com.electronwill.nightconfig.core.utils.StringUtils
Fast string utilities.
-
Method Summary
Modifier and TypeMethodDescriptionSplits a String around each occurence of the specified character.static voidSplits a String around each occurence of the specified character, and puts the result in the given List.splitLines(String str) Splits a String around each occurence of LF and CRLF.static voidsplitLines(String str, List<String> list) Splits a String around each occurence of LF and CRLF, and puts the result in the given list.
-
Method Details
-
split
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
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
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
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
-