Well, it really depends on what you want to achieve. Reading documents for the split method on String and StringUtils , they are very different from each other. And based on your requirements
... want to split each line based on a specific separator.
It seems you need a split method in String
public String[] split(String regex) - Splits this string around matches for this regular expression. (src)
Example:
String str = "abc def"; str.split(" ");
returns:
["abc", "def"]
Because in StringUtils it is:
public static String[] split(String str) - Splits the provided text into an array using whitespace as a separator. (src)
Example:
StringUtils.split("abc def")
returns:
["abc", "def"]
This is an overloaded method, so you can use one that takes a different argument for the separator
public static String[] split(String str, char separatorChar) - Splits the provided text into an array, the specified separator. This is an alternative to using StringTokenizer .
lxcky source share